S
S
Sergey Eremin2016-07-05 20:31:52
Django
Sergey Eremin, 2016-07-05 20:31:52

How can Django set the binary attribute to the varchar field in models?

Actually, the task is to make such a field in the DBMS so that the index on it is built according to the principle of a text field (i.e. "a" in sorting before "aa" ), but inside it could also store binary data data (i.e. distinguished case in comparisons etc). If you do it directly in MySQL, then to get the required one, it is enough to indicate the sign binary for the varchar field. And how to achieve the same models.pythrough Django ?
The Django models binary field doesn't seem to do quite right.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Peter, 2016-07-05
@petermzg

Alternatively, you can create a class inherited from the models.Field
type and override the method in it:

def db_type(self, connection):
        return 'VARBINARY(%s)' % self.max_length

Then in the model you define a field of this class

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question