1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

Converted ChoiceFieldSerializer to display an object

This commit is contained in:
Jeremy Stretch
2017-03-20 16:32:59 -04:00
parent b04fe21d65
commit 2bd46230be

@ -59,7 +59,7 @@ class TokenPermissions(DjangoModelPermissions):
class ChoiceFieldSerializer(Field):
"""
Represent a ChoiceField as (value, label).
Represent a ChoiceField as {'value': <DB value>, 'label': <string>}.
"""
def __init__(self, choices, **kwargs):
self._choices = dict()
@ -73,7 +73,7 @@ class ChoiceFieldSerializer(Field):
super(ChoiceFieldSerializer, self).__init__(**kwargs)
def to_representation(self, obj):
return obj, self._choices[obj]
return {'value': obj, 'label': self._choices[obj]}
def to_internal_value(self, data):
return self._choices.get(data)