mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Closes #4857: Drop support for legacy numeric choice field values
This commit is contained in:
@@ -103,18 +103,11 @@ class ChoiceField(serializers.Field):
|
||||
def to_representation(self, obj):
|
||||
if obj is '':
|
||||
return None
|
||||
data = OrderedDict([
|
||||
return OrderedDict([
|
||||
('value', obj),
|
||||
('label', self._choices[obj])
|
||||
])
|
||||
|
||||
# TODO: Remove in v2.8
|
||||
# Include legacy numeric ID (where applicable)
|
||||
if hasattr(self.choiceset, 'LEGACY_MAP') and obj in self.choiceset.LEGACY_MAP:
|
||||
data['id'] = self.choiceset.LEGACY_MAP.get(obj)
|
||||
|
||||
return data
|
||||
|
||||
def to_internal_value(self, data):
|
||||
if data is '':
|
||||
if self.allow_blank:
|
||||
@@ -140,14 +133,10 @@ class ChoiceField(serializers.Field):
|
||||
try:
|
||||
if data in self._choices:
|
||||
return data
|
||||
# Check if data is a legacy numeric ID
|
||||
slug = self.choiceset.id_to_slug(data)
|
||||
if slug is not None:
|
||||
return slug
|
||||
except TypeError: # Input is an unhashable type
|
||||
pass
|
||||
|
||||
raise ValidationError("{} is not a valid choice.".format(data))
|
||||
raise ValidationError(f"{data} is not a valid choice.")
|
||||
|
||||
@property
|
||||
def choices(self):
|
||||
|
Reference in New Issue
Block a user