mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-17 04:32:51 -06:00
* Fixes #13849: Fix label resolution during serialization for removed field choices * Cleanup
This commit is contained in:
parent
099aff5ebe
commit
3cb41bbe3a
@ -46,11 +46,12 @@ class ChoiceField(serializers.Field):
|
|||||||
return super().validate_empty_values(data)
|
return super().validate_empty_values(data)
|
||||||
|
|
||||||
def to_representation(self, obj):
|
def to_representation(self, obj):
|
||||||
if obj == '':
|
if obj != '':
|
||||||
return None
|
# Use an empty string in place of the choice label if it cannot be resolved (i.e. because a previously
|
||||||
|
# configured choice has been removed from FIELD_CHOICES).
|
||||||
return {
|
return {
|
||||||
'value': obj,
|
'value': obj,
|
||||||
'label': self._choices[obj],
|
'label': self._choices.get(obj, ''),
|
||||||
}
|
}
|
||||||
|
|
||||||
def to_internal_value(self, data):
|
def to_internal_value(self, data):
|
||||||
|
Loading…
Reference in New Issue
Block a user