From f27a28682bdb1b4eea0ec9afca2eb2835c735f55 Mon Sep 17 00:00:00 2001 From: Greg Doermann Date: Wed, 20 Aug 2014 11:00:37 -0600 Subject: [PATCH] Frameworks throws AssertionError saying you cannot set required=True and read_only=True on editable=False model fields. We should not make the field required if editable=False. --- rest_framework/serializers.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/rest_framework/serializers.py b/rest_framework/serializers.py index be8ad3f24..27af7ef33 100644 --- a/rest_framework/serializers.py +++ b/rest_framework/serializers.py @@ -831,7 +831,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: @@ -854,7 +854,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: @@ -1110,7 +1110,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: