Allow blank choices to render. Closes #2071.

This commit is contained in:
Tom Christie 2014-11-19 09:31:26 +00:00
parent f573aaee4e
commit e49d22dbda
2 changed files with 4 additions and 1 deletions

View File

@ -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)]

View File

@ -793,7 +793,8 @@ class TestChoiceField(FieldValues):
'amazing': ['`amazing` is not a valid choice.']
}
outputs = {
'good': 'good'
'good': 'good',
'': ''
}
field = serializers.ChoiceField(
choices=[