mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-22 17:47:04 +03:00
Merge pull request #1785 from gdoermann/master
Frameworks throws AssertionError saying you cannot set required=True and...
This commit is contained in:
commit
0b864acd98
|
@ -845,7 +845,7 @@ class ModelSerializer(Serializer):
|
|||
}
|
||||
|
||||
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:
|
||||
kwargs['help_text'] = model_field.help_text
|
||||
if model_field.verbose_name is not None:
|
||||
|
@ -868,7 +868,7 @@ class ModelSerializer(Serializer):
|
|||
"""
|
||||
kwargs = {}
|
||||
|
||||
if model_field.null or model_field.blank:
|
||||
if model_field.null or model_field.blank and model_field.editable:
|
||||
kwargs['required'] = False
|
||||
|
||||
if isinstance(model_field, models.AutoField) or not model_field.editable:
|
||||
|
@ -1126,7 +1126,7 @@ class HyperlinkedModelSerializer(ModelSerializer):
|
|||
}
|
||||
|
||||
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:
|
||||
kwargs['help_text'] = model_field.help_text
|
||||
if model_field.verbose_name is not None:
|
||||
|
|
Loading…
Reference in New Issue
Block a user