Merge pull request #1785 from gdoermann/master

Frameworks throws AssertionError saying you cannot set required=True and...
This commit is contained in:
Tom Christie 2014-10-31 15:29:06 +00:00
commit 0b864acd98

View File

@ -845,7 +845,7 @@ class ModelSerializer(Serializer):
} }
if model_field: if model_field:
kwargs['required'] = not(model_field.null or model_field.blank) kwargs['required'] = not(model_field.null or model_field.blank) and model_field.editable
if model_field.help_text is not None: if model_field.help_text is not None:
kwargs['help_text'] = model_field.help_text kwargs['help_text'] = model_field.help_text
if model_field.verbose_name is not None: if model_field.verbose_name is not None:
@ -868,7 +868,7 @@ class ModelSerializer(Serializer):
""" """
kwargs = {} kwargs = {}
if model_field.null or model_field.blank: if model_field.null or model_field.blank and model_field.editable:
kwargs['required'] = False kwargs['required'] = False
if isinstance(model_field, models.AutoField) or not model_field.editable: if isinstance(model_field, models.AutoField) or not model_field.editable:
@ -1126,7 +1126,7 @@ class HyperlinkedModelSerializer(ModelSerializer):
} }
if model_field: if model_field:
kwargs['required'] = not(model_field.null or model_field.blank) kwargs['required'] = not(model_field.null or model_field.blank) and model_field.editable
if model_field.help_text is not None: if model_field.help_text is not None:
kwargs['help_text'] = model_field.help_text kwargs['help_text'] = model_field.help_text
if model_field.verbose_name is not None: if model_field.verbose_name is not None: