I use the django admin for updating various data on the MySQL database. I use the basic django admin for this. When entering in new data, I would like to be able to have it so people can only select from a few options to enter in new text data.
For example:
The table holds colors, so instead of letting the admin person (data entry individual in our case) just enter in anything into the text box, how can I get the django admin to only give them several options to choose from?
This can be done via the model field argument
choicesThe only problem with this is that if you already have a value in the database that doesn’t match one of these, django might just default it to one of the choices.
If that’s a problem and you want to preserve those values, I might override the admin form and either only supply the
ChoiceFieldon add operations or dynamically add whatever is in the DB as one of the valid choices.