Skip to content
Snippets Groups Projects
Commit f87b3392 authored by Tanner Prestegard's avatar Tanner Prestegard Committed by GraceDB
Browse files

New choice-type field that shows display value

Created ChoiceDisplayField - same as ChoiceField, except its
to_representation() used the display value instead of the key.
parent d781b0e6
No related branches found
No related tags found
1 merge request!8Superevents
......@@ -64,3 +64,12 @@ class CommaSeparatedOrListField(fields.ListField):
data = data[0].split(',')
return super(CommaSeparatedOrListField, self).to_internal_value(data)
class ChoiceDisplayField(fields.ChoiceField):
"""
Same as standard choice field, but return a choice's display_value
instead of the key when serializing the field.
"""
def to_representation(self, value):
return self._choices[value]
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment