Entity with properties mapped on blob/text sql field - drupal-8

I Have an entity (taht extends Drupal\Core\Entity\ContentEntityBase). I try to map some property of this entity on blob or text mysql field.
In the documentation, I don't see wichh value I have to put in BaseFieldDefinition::create(VALUE ???).
Maybe it's not possible ??

Core field types:
boolean
changed
comment
created
datetime
decimal
email
entity_reference
file
float
image
integer
language
link
list_float
list_integer
list_string
map
password
path
string
string_long
telephone
text
text_long
text_with_summary
timestamp
uri
uuid
Documented HERE

Related

Get instance by file name for a file in ImageField

Django 3.1.6
class ResponsiveImage(models.Model):
responsive_image = models.ImageField(upload_to=_raster_img_upload_to)
I want to find an instance by the image file_name:
file_name = 'img/raster/0a8449e7-8e50-4c02-853e-59a25592770d/img_144_96_fallback_3x_4.fallback'
ResponsiveImage.objects.get(responsive_image__name=file_name)
But this gets an error:
{FieldError}Unsupported lookup 'name' for ImageField or join on the field not permitted.
Could you help me?
When an ImageField is saved the string for the relative path to the image is stored in the database for your ResponsiveImage object for the field responsive_image.
You should be able to just go
ResponsiveImage.objects.get(responsive_image=file_name)
To get a specific ResponsiveImage object (As long as it actually exists in the database).

Updating The name of already existing field to something else in NiFi

Is there a way I can update the name of existing field in the CSV file to a new name. I know we can use updaterecord processor. But can someone tell me what config to set?
Current i am using CSVreader and CSVSetWritter with Recordpath value and adding a new property:
Property Value
/oldname ${field.name:replace('oldname','newname')}
It is not changing the name of the field. Can anyone help me here? thank you!
Keep your csv reader controller service with old name and csv Writer controller service with new name for the field.
Then swap the data from old name -> new name
UpdateRecord configs:
As Replacement Value Strategy
Record Path Value
Add new property as
/newname value as
/oldname
For more details refer to this article as i have swapped the data from id field to rename_id field.

Serializing enum fields spring data solr

I have this field in my domain object
#Field
#Enumerated(EnumType.STRING)
private SectionType sectionType;
but when I check the value stored in Solr it is something like:
com.x.y.objects.SectionType:H_HPI
What I want is just H_HPI or it is as if I'm calling specialty.name() method
Also I want a serializer that does that for all the enum fields in my domain objects.
I know that for neo4j, for instance, has such a serializer and can be supplied to the field as an annotation. Also mongodb does the conversion automatically.
I had same problem and found this from Spring Data Solr codes
else if (fieldValue instanceof Enum) {
field.setValue(this.getConversionService().convert(fieldValue, String.class), 1f);
}
it sets the String value
https://github.com/spring-projects/spring-data-solr/commit/4bf0af3344ec9e92ac241eaa25883e73b08f3b0b

Django unable to save a text value in DB

I'm reading an e-mail content through IMAP in my Django app.
When I try to assign some of the parsed content to the object and do .save() it returns:
ProgrammingError: You must not use 8-bit bytestrings unless you use a text_factory that can interpret 8-bit bytestrings (like text_factory = str). It is highly recommended that you instead just switch your application to Unicode strings.
When I print the variable type: . Field in the DB is defined as CharField. I tried TextField as well, but the result is the same.
How I can solve that?
if your mail text is in mail_text, do this:
mail_text = unicode(mail_text)

Get value in a post request, Django

am getting the following post data in my django app
POST
Variable Value
csrfmiddlewaretoken u'LHM3nkrrrrrrrrrrrrrrrrrrrrrrrrrdd'
id u'{"docs":[],"dr":1, "id":4, "name":"Group", "proj":"/al/p1/proj/2/", "resource":"/al/p1/dgroup/4/","route":"group", "parent":null'
am trying to get the id value in variable id i.e "id":4 (the value 4). When I do request.POST.get('id')I get the whole json string. u'{"docs":[],"dr":1, "id":4, "name":"Group", "proj":"/al/p1/proj/2/", "resource":"/al/p1/dgroup/4/","route":"group", "parent":null' How can I get the "id" in the string?
The data you are sending is simply a json string.
You have to parse that string before you can access data within it. For this you can use Python's json module (it should be available if you're using Python 2.7).
import json
data = json.loads( request.POST.get('id') )
id = data["id"]
If you somehow don't have the json module, you can get the simplejson module.
For more details, refer this question : best way to deal with JSON in django
That's happening because id is string, not dict as it should be. Please provide your template and view code to find source of problem.