Commit e1bbe9d5 by Yuri Prezument

Set `allow_none = True` for CharFields with null=True

parent 6e622d64
...@@ -821,10 +821,15 @@ class ModelSerializer(Serializer): ...@@ -821,10 +821,15 @@ class ModelSerializer(Serializer):
kwargs.update({attribute: getattr(model_field, attribute)}) kwargs.update({attribute: getattr(model_field, attribute)})
try: try:
return self.field_mapping[model_field.__class__](**kwargs) field_class = self.field_mapping[model_field.__class__]
except KeyError: except KeyError:
return ModelField(model_field=model_field, **kwargs) 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): def get_validation_exclusions(self):
""" """
Return a list of field names to exclude from model validation. Return a list of field names to exclude from model validation.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment