From afe7ed9333e37384f8ddc57e891da9632c8714c3 Mon Sep 17 00:00:00 2001 From: José Padilla Date: Tue, 9 Dec 2014 09:25:06 -0400 Subject: Add allow_blank for ChoiceField #2184 This makes a ChoiceField optional in HTML if model field has `blank=True` set.--- rest_framework/utils/field_mapping.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'rest_framework/utils/field_mapping.py') diff --git a/rest_framework/utils/field_mapping.py b/rest_framework/utils/field_mapping.py index 9c187176..86ceff31 100644 --- a/rest_framework/utils/field_mapping.py +++ b/rest_framework/utils/field_mapping.py @@ -91,18 +91,18 @@ def get_field_kwargs(field_name, model_field): if model_field.has_default() or model_field.blank or model_field.null: kwargs['required'] = False - if model_field.flatchoices: - # If this model field contains choices, then return early. - # Further keyword arguments are not valid. - kwargs['choices'] = model_field.flatchoices - return kwargs - if model_field.null and not isinstance(model_field, models.NullBooleanField): kwargs['allow_null'] = True if model_field.blank: kwargs['allow_blank'] = True + if model_field.flatchoices: + # If this model field contains choices, then return early. + # Further keyword arguments are not valid. + kwargs['choices'] = model_field.flatchoices + return kwargs + # Ensure that max_length is passed explicitly as a keyword arg, # rather than as a validator. max_length = getattr(model_field, 'max_length', None) -- cgit v1.2.3 From 7d70e56ce378a7876a0fd7f29b52a492e46053b9 Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Tue, 9 Dec 2014 16:25:10 +0000 Subject: Copy model field validators, don't reuse the same list. --- rest_framework/utils/field_mapping.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'rest_framework/utils/field_mapping.py') diff --git a/rest_framework/utils/field_mapping.py b/rest_framework/utils/field_mapping.py index 86ceff31..fca97b4b 100644 --- a/rest_framework/utils/field_mapping.py +++ b/rest_framework/utils/field_mapping.py @@ -59,7 +59,7 @@ def get_field_kwargs(field_name, model_field): Creates a default instance of a basic non-relational field. """ kwargs = {} - validator_kwarg = model_field.validators + validator_kwarg = list(model_field.validators) # The following will only be used by ModelField classes. # Gets removed for everything else. -- cgit v1.2.3