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

Fixes #1226: Improve validation for custom field values submitted via the API

This commit is contained in:
Jeremy Stretch
2017-05-31 14:09:57 -04:00
parent f03a378ce0
commit 293dbd8a8b
2 changed files with 26 additions and 5 deletions

View File

@@ -139,7 +139,11 @@ class CustomField(models.Model):
if self.type == CF_TYPE_BOOLEAN:
return str(int(bool(value)))
if self.type == CF_TYPE_DATE:
return value.strftime('%Y-%m-%d')
# Could be date/datetime object or string
try:
return value.strftime('%Y-%m-%d')
except AttributeError:
return value
if self.type == CF_TYPE_SELECT:
# Could be ModelChoiceField or TypedChoiceField
return str(value.id) if hasattr(value, 'id') else str(value)