mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-17 04:32:51 -06:00
Converted ChoiceFieldSerializer to display an object
This commit is contained in:
parent
b04fe21d65
commit
2bd46230be
@ -59,7 +59,7 @@ class TokenPermissions(DjangoModelPermissions):
|
|||||||
|
|
||||||
class ChoiceFieldSerializer(Field):
|
class ChoiceFieldSerializer(Field):
|
||||||
"""
|
"""
|
||||||
Represent a ChoiceField as (value, label).
|
Represent a ChoiceField as {'value': <DB value>, 'label': <string>}.
|
||||||
"""
|
"""
|
||||||
def __init__(self, choices, **kwargs):
|
def __init__(self, choices, **kwargs):
|
||||||
self._choices = dict()
|
self._choices = dict()
|
||||||
@ -73,7 +73,7 @@ class ChoiceFieldSerializer(Field):
|
|||||||
super(ChoiceFieldSerializer, self).__init__(**kwargs)
|
super(ChoiceFieldSerializer, self).__init__(**kwargs)
|
||||||
|
|
||||||
def to_representation(self, obj):
|
def to_representation(self, obj):
|
||||||
return obj, self._choices[obj]
|
return {'value': obj, 'label': self._choices[obj]}
|
||||||
|
|
||||||
def to_internal_value(self, data):
|
def to_internal_value(self, data):
|
||||||
return self._choices.get(data)
|
return self._choices.get(data)
|
||||||
|
Loading…
Reference in New Issue
Block a user