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

Add object_type validation

This commit is contained in:
jeremystretch
2022-01-06 13:43:40 -05:00
parent 1e80cc6db5
commit bfc695434c

View File

@ -242,6 +242,17 @@ class CustomField(ChangeLoggedModel):
'default': f"The specified default value ({self.default}) is not listed as an available choice."
})
# Object fields must define an object_type; other fields must not
if self.type in (CustomFieldTypeChoices.TYPE_OBJECT, CustomFieldTypeChoices.TYPE_MULTIOBJECT):
if not self.object_type:
raise ValidationError({
'object_type': "Object fields must define an object type."
})
elif self.object_type:
raise ValidationError({
'object_type': f"{self.get_type_display()} fields may not define an object type."
})
def serialize(self, value):
"""
Prepare a value for storage as JSON data.