Wednesday, January 23, 2019

Charfield variable length

Hello

I have problems with the Charfield max_length. In the source code, the possibility exists to have max_length = None but it does not pass Django check when  models.py. contains a charfield = None

I can understand that there is a need for such a max_length form the database point of view .
My need is the following:

I have a set of  fields whose content in the database is a binary code of maximum 180 bits. Most of the time it will be much shorter and there is  in the form a field (max size) giving this maximum size.

The user needs to input this field in the database as a Character string of 0 and 1. using hexadecimal fields would be very unpractical. Last but not least, I am using the admin to enter these data in the database.

In a first shot, I used a Charfield and I overwrote the field in the init to set the maximum length to the value chosen by the user. I also modifed the attributes of the widget. But at the end the HTML contains a texinput with the max length set in the model. 

Is this an admin feature or did I miss something?

. Any other suggestion on how to handle these fields would be welcomed.

No comments:

Post a Comment