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

Fixes #2609: Fixed exception when ChoiceField integer value is passed as a string

This commit is contained in:
Jeremy Stretch
2018-11-26 14:05:57 -05:00
parent 2bae50f501
commit 7d8ae5e763
2 changed files with 7 additions and 1 deletions

View File

@ -78,12 +78,17 @@ class ChoiceField(Field):
return data
def to_internal_value(self, data):
# Hotwiring boolean values
if hasattr(data, 'lower'):
# Hotwiring boolean values from string
if data.lower() == 'true':
return True
if data.lower() == 'false':
return False
# Check for string representation of an integer (e.g. "123")
try:
data = int(data)
except ValueError:
pass
return data