Add searchable named-identifier (display-name) to models and REST API #11008

Closed
opened 2025-12-29 21:39:07 +01:00 by adam · 0 comments
Owner

Originally created by @arthanson on GitHub (Apr 10, 2025).

NetBox version

v4.2.6

Feature type

Data model extension

Proposed functionality

Add a field to all models (display-name or display-identifier)? that is a cached searchable named identifier for each object. There is q for the search API but that includes other fields. There isn't currently an easy way programmatically and through the API to get an object by its display name.

The REST API returns display which is what we want, but this is not a filterable field and it comes from the str of the model. Each model has different rules as to what the display name is as some models don't have name or the name is optional. For example str on Device (https://github.com/netbox-community/netbox/blob/main/netbox/dcim/models/devices.py#L804) goes through several fields.

A new field could be added to the model and this display-name could be saved from str. This field can then be added to filtersets, this would allow both the REST API to find things by their display name, and also allow easy filtering by the ORM. It is okay if these are not unique.

It would make most sense to implement this as a base level mixin that every model inherits from (and plugins can as well). This would add a model field and in save just store str into it. It would also potentially make the search function easier as you could replace several of the model specific fields with this field.

Use case

This has been run into with some plugins and extensions (like Assurance) where they want to match objects by name and there is currently no easy way of doing this as each model has different properties to determine what it's display name is.

Database changes

Would need a new field added to all models.

External dependencies

N/A

Originally created by @arthanson on GitHub (Apr 10, 2025). ### NetBox version v4.2.6 ### Feature type Data model extension ### Proposed functionality Add a field to all models (display-name or display-identifier)? that is a cached searchable named identifier for each object. There is q for the search API but that includes other fields. There isn't currently an easy way programmatically and through the API to get an object by its display name. The REST API returns display which is what we want, but this is not a filterable field and it comes from the __str__ of the model. Each model has different rules as to what the display name is as some models don't have name or the name is optional. For example __str__ on Device (https://github.com/netbox-community/netbox/blob/main/netbox/dcim/models/devices.py#L804) goes through several fields. A new field could be added to the model and this display-name could be saved from __str__. This field can then be added to filtersets, this would allow both the REST API to find things by their display name, and also allow easy filtering by the ORM. It is okay if these are not unique. It would make most sense to implement this as a base level mixin that every model inherits from (and plugins can as well). This would add a model field and in save just store str into it. It would also potentially make the search function easier as you could replace several of the model specific fields with this field. ### Use case This has been run into with some plugins and extensions (like Assurance) where they want to match objects by name and there is currently no easy way of doing this as each model has different properties to determine what it's display name is. ### Database changes Would need a new field added to all models. ### External dependencies N/A
adam added the type: feature label 2025-12-29 21:39:07 +01:00
adam closed this issue 2025-12-29 21:39:07 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#11008