diff options
| author | Tom Christie | 2014-12-09 14:08:45 +0000 |
|---|---|---|
| committer | Tom Christie | 2014-12-09 14:08:45 +0000 |
| commit | 54a18a4ddb69bb43c13e45f151b075564dd771b2 (patch) | |
| tree | c392eb5c1afba4dee29d67c2e67411b957371bdf /rest_framework/utils | |
| parent | cae19f8924c598cea93a546138757ff48eed9f75 (diff) | |
| parent | afe7ed9333e37384f8ddc57e891da9632c8714c3 (diff) | |
| download | django-rest-framework-54a18a4ddb69bb43c13e45f151b075564dd771b2.tar.bz2 | |
Merge pull request #2239 from jpadilla/allow-blank-choicefield
Add allow_blank for ChoiceField #2184
Diffstat (limited to 'rest_framework/utils')
| -rw-r--r-- | rest_framework/utils/field_mapping.py | 12 |
1 files changed, 6 insertions, 6 deletions
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) |
