Django model choice not raising error for an invalid choice

UPDATE

Since django 2.1, setting choices does raise validation errors:

If choices are given, they’re enforced by model validation and the default form widget will be a select box with these choices instead of the standard text field.

Note that, CustomFieldType.objects.create is not enough. You need to do something like a model_instance.full_clean() to raise the error. Just as mentioned in the model validation docs


The choices option is only for pre-populating of form drop down fields; it does not enforce any validation:

If this is given, the default form widget will be a select box with these choices instead of the standard text field.

Tags:

Python

Django