python - Django: How to model a MySQL VARBINARY HEX Field? -
I am trying to model a VARBINARY
MySQL field in Django v1.1.1. Binary field represents a hexadecimal data (i.e. any one will use INSERT INTO test (bin_val) VALUES X'4D7953514C '
)
Reading Django document [1] I came With this solution:
class MyTest (models.Model): bin_val = BinValField () class BinValField (models.Field): __metaclass__ = models.SubfieldBase def to_python (self, value): " "Db -> For the value of the byte ('% x% X'% ((ord (byte))> 4) & amp; 0xF, ord (byte) and 0xF)) Def ('' Latin 1 '') )
However, this does not work correctly because
- Django makes a Unicode change of binary data from MySQL
- When saving a new MyTest object, called
get_db_prep_value ()
twice (I think this is a bug in Django?)
The question is How would you prepare such an area?
PS: Related to this problem The ticket is [2] which has still been opened after 3 years: (
[1] Django: Writing custom model field
[2]
The problem creates jezos database tables and was also related
- The table charset The code has been changed to
utf8
and.
VARCHAR < / Code> to
VARBINARY
in the MySQL table- has been changed> To_python
return hexlif (value)
Comments
Post a Comment