diff --git a/docs/customization/custom-fields.md b/docs/customization/custom-fields.md index 1e500d203..4658cc7e6 100644 --- a/docs/customization/custom-fields.md +++ b/docs/customization/custom-fields.md @@ -74,7 +74,7 @@ If a default value is specified for a selection field, it must exactly match one An object or multi-object custom field can be used to refer to a particular NetBox object or objects as the "value" for a custom field. These custom fields must define an `object_type`, which determines the type of object to which custom field instances point. -By default, an object choice field will make all objects of that type available for selection in the drop-down. The list choices can be filtered to only show objects with certain values by providing a `query_params` dict in the Related Object Filter field, as a JSON value. More information about `query_params` can be found [here](./custom-scripts.md#objectvar) +By default, an object choice field will make all objects of that type available for selection in the drop-down. The list choices can be filtered to show only objects with certain values by providing a `query_params` dict in the Related Object Filter field, as a JSON value. More information about `query_params` can be found [here](./custom-scripts.md#objectvar). ## Custom Fields in Templates diff --git a/docs/models/extras/customfield.md b/docs/models/extras/customfield.md index 2353bc2b9..164ce3a74 100644 --- a/docs/models/extras/customfield.md +++ b/docs/models/extras/customfield.md @@ -42,6 +42,13 @@ The type of data this field holds. This must be one of the following: For object and multiple-object fields only. Designates the type of NetBox object being referenced. +### Related Object Filter + +For object and multi-object custom fields, a filter may be defined to limit the available objects when populating a field value. This filter maps object attributes to values. For example, `{"status": "active"}` will include only objects with a status of "active." + +!!! warning + This setting is employed for convenience only, and should not be relied upon to enforce data integrity. + ### Weight A numeric weight used to override alphabetic ordering of fields by name. Custom fields with a lower weight will be listed before those with a higher weight. (Note that weight applies within the context of a custom field group, if defined.) diff --git a/netbox/templates/extras/customfield.html b/netbox/templates/extras/customfield.html index 85a3c6cd3..dffdbbd93 100644 --- a/netbox/templates/extras/customfield.html +++ b/netbox/templates/extras/customfield.html @@ -54,7 +54,11 @@ {% trans "Related object filter" %} - {{ object.related_object_filter }} + {% if object.related_object_filter %} +
{{ object.related_object_filter|json }}
+ {% else %} + {{ ''|placeholder }} + {% endif %}