mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-14 05:36:50 +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)
|
self.fail('invalid_choice', input=data)
|
||||||
|
|
||||||
def to_representation(self, value):
|
def to_representation(self, value):
|
||||||
|
if value in ('', None):
|
||||||
|
return value
|
||||||
return self.choice_strings_to_values[six.text_type(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.']
|
'amazing': ['`amazing` is not a valid choice.']
|
||||||
}
|
}
|
||||||
outputs = {
|
outputs = {
|
||||||
'good': 'good'
|
'good': 'good',
|
||||||
|
'': ''
|
||||||
}
|
}
|
||||||
field = serializers.ChoiceField(
|
field = serializers.ChoiceField(
|
||||||
choices=[
|
choices=[
|
||||||
|
|
Loading…
Reference in New Issue
Block a user