Last active
August 29, 2015 14:21
-
-
Save shangxiao/93b983ea2313aa71137a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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