From 206859529780adbe7f49ee1e4d466e3b4fe13099 Mon Sep 17 00:00:00 2001 From: Marko Tibold Date: Tue, 30 Oct 2012 00:09:40 +0100 Subject: [PATCH] Set a ModelSerializer field to required=False if the ModelField has null=True set. --- rest_framework/serializers.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/rest_framework/serializers.py b/rest_framework/serializers.py index ce04b3e20..e705bf772 100644 --- a/rest_framework/serializers.py +++ b/rest_framework/serializers.py @@ -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()