mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-08 00:28:16 -06:00
Add validation for related_object_filter
This commit is contained in:
parent
c2b36df377
commit
8a594d0a49
@ -381,6 +381,17 @@ class CustomField(CloningMixin, ExportTemplatesMixin, ChangeLoggedModel):
|
||||
.format(type=self.get_type_display())
|
||||
})
|
||||
|
||||
# Related object filter can be set only for object-type fields, and must contain a dictionary mapping (if set)
|
||||
if self.related_object_filter is not None:
|
||||
if self.type not in (CustomFieldTypeChoices.TYPE_OBJECT, CustomFieldTypeChoices.TYPE_MULTIOBJECT):
|
||||
raise ValidationError({
|
||||
'related_object_filter': _("A related object filter can be defined only for object fields.")
|
||||
})
|
||||
if type(self.related_object_filter) is not dict:
|
||||
raise ValidationError({
|
||||
'related_object_filter': _("Filter must be defined as a dictionary mapping attributes to values.")
|
||||
})
|
||||
|
||||
def serialize(self, value):
|
||||
"""
|
||||
Prepare a value for storage as JSON data.
|
||||
|
Loading…
Reference in New Issue
Block a user