diff options
| author | Yuri Prezument | 2014-01-12 16:30:26 +0200 |
|---|---|---|
| committer | Yuri Prezument | 2014-01-12 16:32:36 +0200 |
| commit | cd9a4194ea4f4dc0e43a34485cd8a27eba44a39a (patch) | |
| tree | 219a03e808f239c6ca7d5e270fb278b78788a0ad /rest_framework/serializers.py | |
| parent | 0fd0454a5c1ddcf8676e23b30dfaee40fa7cb0c8 (diff) | |
| download | django-rest-framework-cd9a4194ea4f4dc0e43a34485cd8a27eba44a39a.tar.bz2 | |
Check the modelfield's class instead
Diffstat (limited to 'rest_framework/serializers.py')
| -rw-r--r-- | rest_framework/serializers.py | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/rest_framework/serializers.py b/rest_framework/serializers.py index 0164965c..cbf73fc3 100644 --- a/rest_framework/serializers.py +++ b/rest_framework/serializers.py @@ -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. |
