mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-06 13:30:12 +03:00
add KeyError exception with valid choice message.
This commit is contained in:
parent
4f1506c77e
commit
af30319f3b
|
@ -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 = {
|
||||
|
|
Loading…
Reference in New Issue
Block a user