mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-22 17:47:04 +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