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:
@ -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.
|
||||
|
Reference in New Issue
Block a user