Commit e49d22db by Tom Christie

Allow blank choices to render. Closes #2071.

parent f573aaee
...@@ -947,6 +947,8 @@ class ChoiceField(Field): ...@@ -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): ...@@ -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=[
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment