mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-10 19:56:59 +03:00
Check the modelfield's class instead
This commit is contained in:
parent
0fd0454a5c
commit
cd9a4194ea
|
@ -804,6 +804,10 @@ class ModelSerializer(Serializer):
|
|||
issubclass(model_field.__class__, models.PositiveSmallIntegerField):
|
||||
kwargs['min_value'] = 0
|
||||
|
||||
if model_field.null and \
|
||||
issubclass(model_field.__class__, (models.CharField, models.TextField)):
|
||||
kwargs['allow_none'] = True
|
||||
|
||||
attribute_dict = {
|
||||
models.CharField: ['max_length'],
|
||||
models.CommaSeparatedIntegerField: ['max_length'],
|
||||
|
@ -821,15 +825,10 @@ class ModelSerializer(Serializer):
|
|||
kwargs.update({attribute: getattr(model_field, attribute)})
|
||||
|
||||
try:
|
||||
field_class = self.field_mapping[model_field.__class__]
|
||||
return self.field_mapping[model_field.__class__](**kwargs)
|
||||
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