mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-01 19:10:12 +03:00
Fix issue with validation of NullBooleanField
with choices
`get_field_kwargs` function will not set `allow_null` kwarg to `True` for `models.NullBooleanField`. But in case choices provided for this field we need to set `allow_null` to `True`, since all fields with provided choices will be validated as `ChoiceField` (see `ModelSerializer.build_standard_field(...)`).
This commit is contained in:
parent
9dfee6cd7b
commit
527411ce92
|
@ -100,7 +100,8 @@ def get_field_kwargs(field_name, model_field):
|
||||||
if model_field.has_default() or model_field.blank or model_field.null:
|
if model_field.has_default() or model_field.blank or model_field.null:
|
||||||
kwargs['required'] = False
|
kwargs['required'] = False
|
||||||
|
|
||||||
if model_field.null and not isinstance(model_field, models.NullBooleanField):
|
is_null_boolean_field = isinstance(model_field, models.NullBooleanField)
|
||||||
|
if (model_field.null and not is_null_boolean_field) or (model_field.choices and is_null_boolean_field):
|
||||||
kwargs['allow_null'] = True
|
kwargs['allow_null'] = True
|
||||||
|
|
||||||
if model_field.blank and (isinstance(model_field, models.CharField) or
|
if model_field.blank and (isinstance(model_field, models.CharField) or
|
||||||
|
|
Loading…
Reference in New Issue
Block a user