Set allow_none = True for CharFields with null=True

This commit is contained in:
Yuri Prezument 2014-01-06 13:56:57 +02:00
parent 6e622d644c
commit e1bbe9d514

View File

@ -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.