12👍
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.
4👍
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
- Django Rest Framework receive primary key value in POST and return model object as nested serializer
- Django form dropdown with all users in it
0👍
I faced same problem, and I solved it by using save()
method instead of create()
method, and you must use full_clean()
before it. like this:
x = "your model name"()
x."field" = "value"
.
.
.
"your model name".full_clean(self = x)
"your model name".save(self = x)
- Where do I put "WSGIPassAuthorization On"?
- How to do pagination using mongoengine?
- Django `SECRET_KEY` settings
- Django multi-table inheritance, how to know which is the child class of a model?
- Retrieving the 'many' end of a Generic Foreign Key relationship in Django