Closed
Description
NetBox version
v3.7.4
Feature type
New functionality
Proposed functionality
When defining custom validation rules as JSON, it is currently possible to access only direct attributes on an object. For example:
CUSTOM_VALIDATORS = {
"dcim.site": [
{
"name": {
"min_length": 5,
}
}
]
}
It is not possible to reference an attribute of a related object; this would require creating a CustomValidator subclass in Python with a custom validate()
method as discussed here.
This issue proposes a mechanism for referencing attributes of related objects, identified by a dotted path. For example, the following would reference a the name of a site's assigned region:
CUSTOM_VALIDATORS = {
"dcim.site": [
{
"region.name": {
"eq": "North Carolina",
}
}
]
}
This could be achieved by employing Python's operator.attrgetter()
utility.
Use case
This enhancement will allow users to reach "deeper" into an object when validating it without the need to write a custom subclass in Python.
Database changes
None
External dependencies
None