Set a ModelSerializer field to required=False if the ModelField has null=True set.

This commit is contained in:
Marko Tibold 2012-10-30 00:09:40 +01:00
parent 6ccbdd10ad
commit 2068595297

View File

@ -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()