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

Fixes #1297: Allow passing custom field choice selection PKs as string-quoted integers

This commit is contained in:
Jeremy Stretch
2017-07-05 11:00:43 -04:00
parent 25ee796d5b
commit 1d4a416100

View File

@ -49,6 +49,10 @@ class CustomFieldsSerializer(serializers.BaseSerializer):
# Validate selected choice
if cf.type == CF_TYPE_SELECT:
try:
value = int(value)
except ValueError:
raise ValidationError("{}: Choice selections must be passed as integers.".format(field_name))
valid_choices = [c.pk for c in cf.choices.all()]
if value not in valid_choices:
raise ValidationError("Invalid choice for field {}: {}".format(field_name, value))