mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-01-23 15:54:16 +03:00
Set a ModelSerializer field to required=False if the ModelField has null=True set.
This commit is contained in:
parent
6ccbdd10ad
commit
2068595297
|
@ -393,6 +393,9 @@ class ModelSerializer(Serializer):
|
|||
Creates a default instance of a basic non-relational field.
|
||||
"""
|
||||
kwargs = {}
|
||||
if model_field.null:
|
||||
kwargs['required'] = False
|
||||
|
||||
if model_field.has_default():
|
||||
kwargs['required'] = False
|
||||
kwargs['default'] = model_field.get_default()
|
||||
|
|
Loading…
Reference in New Issue
Block a user