Skip to content

Instantly share code, notes, and snippets.

@shangxiao
Last active August 29, 2015 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shangxiao/93b983ea2313aa71137a to your computer and use it in GitHub Desktop.
Save shangxiao/93b983ea2313aa71137a to your computer and use it in GitHub Desktop.
class ChoiceField(Field):
...
def to_representation(self, value):
if data == '' and self.allow_blank:
return ''
try:
return self.choice_strings_to_values[six.text_type(value)]
except KeyError:
return value
class MultipleChoiceField(ChoiceField):
...
def to_representation(self, value):
return set([
self.choice_strings_to_values[six.text_type(item)]
if six.text_type(value) in self.choice_strings_to_values
else item
for item in value
])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment