Thursday, February 23, 2017

Re: Issues saving hex format data to binaryfield

Notice how Brian print self.rfid before and after affecting the new value.
The second print should display the updated data. As it is not the
case, I highly doubt save will change the value in db.


Ok, look like I misread the code when writing my previous reply.
Now I'm all curious about how did you find about the editable argument
and why you set it.
About your problem, django's BinaryField is not editable. Here is the
source for django 1.10.5 [1]
Notice how the init method override your argument ? I haven't checked
further but I'm pretty sure
it explain the issue you have noticed.

Doing a raw SQL query to update the RFID value is probably your best
option. Here is the doc [2]

[1] https://github.com/django/django/blob/1.10.5/django/db/models/fields/__init__.py#L2306
[2] https://docs.djangoproject.com/en/1.10/topics/db/sql/#executing-custom-sql-directly

2017-02-23 10:47 GMT+01:00 Melvyn Sopacua <m.r.sopacua@gmail.com>:
> On Wednesday 22 February 2017 14:47:55 Brian O'Connell wrote:
>
>
>
>> def set_rfid(self,rfid_new):
>
>> print self.rfid # print the existing object data
>
>> try:
>
>> self.rfid = bytearray(rfid_new)
>
>> print self.rfid
>
>> except Exception as ex:
>
>> template = "An exception of type {0} occured.
>
>> Arguments:\n{1!r}" message = template.format(type(ex).__name__,
>
>> ex.args) print message
>
>>
>
>> It doesn't raise an exception but it also doesn't save it into the
>
>> field.
>
>
>
> Because this is set_rfid not save(). If you call save() after calling
> set_rfid, the value isn't saved?
>
> --
>
> Melvyn Sopacua
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscribe@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/10747751.VrTcuDJZbZ%40devstation.
>
> For more options, visit https://groups.google.com/d/optout.



--

Cordialement, Coues Ludovic
+336 148 743 42

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAEuG%2BTZd%3DVEu4vuab3zvGv4caUaCdH20hTTrQYOE4snYXP5_2w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment