mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-26 03:23:59 +03:00
Allow blank choices to render. Closes #2071.
This commit is contained in:
parent
f573aaee4e
commit
e49d22dbda
|
@ -947,6 +947,8 @@ class ChoiceField(Field):
|
|||
self.fail('invalid_choice', input=data)
|
||||
|
||||
def to_representation(self, value):
|
||||
if value in ('', None):
|
||||
return value
|
||||
return self.choice_strings_to_values[six.text_type(value)]
|
||||
|
||||
|
||||
|
|
|
@ -793,7 +793,8 @@ class TestChoiceField(FieldValues):
|
|||
'amazing': ['`amazing` is not a valid choice.']
|
||||
}
|
||||
outputs = {
|
||||
'good': 'good'
|
||||
'good': 'good',
|
||||
'': ''
|
||||
}
|
||||
field = serializers.ChoiceField(
|
||||
choices=[
|
||||
|
|
Loading…
Reference in New Issue
Block a user