mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-22 17:47:04 +03:00
Set allow_none = True
for CharFields with null=True
This commit is contained in:
parent
6e622d644c
commit
e1bbe9d514
|
@ -821,10 +821,15 @@ class ModelSerializer(Serializer):
|
|||
kwargs.update({attribute: getattr(model_field, attribute)})
|
||||
|
||||
try:
|
||||
return self.field_mapping[model_field.__class__](**kwargs)
|
||||
field_class = self.field_mapping[model_field.__class__]
|
||||
except KeyError:
|
||||
return ModelField(model_field=model_field, **kwargs)
|
||||
|
||||
if issubclass(field_class, CharField) and model_field.null:
|
||||
kwargs['allow_none'] = True
|
||||
|
||||
return field_class(**kwargs)
|
||||
|
||||
def get_validation_exclusions(self):
|
||||
"""
|
||||
Return a list of field names to exclude from model validation.
|
||||
|
|
Loading…
Reference in New Issue
Block a user