add KeyError exception with valid choice message.

This commit is contained in:
Matt Bartolome 2015-02-18 10:31:50 -08:00
parent 4f1506c77e
commit af30319f3b

View File

@ -1024,8 +1024,11 @@ class ChoiceField(Field):
def to_representation(self, value):
if value in ('', None):
return value
return self.choice_strings_to_values[six.text_type(value)]
try:
return self.choice_strings_to_values[six.text_type(value)]
except KeyError:
self.fail('invalid_choice', input=value)
class MultipleChoiceField(ChoiceField):
default_error_messages = {