mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-03 12:00:12 +03:00
Set allow_none = True
for CharFields with null=True
This commit is contained in:
parent
349205d218
commit
bc61d01737
|
@ -836,10 +836,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