mirror of
https://github.com/netbox-community/netbox.git
synced 2026-04-01 23:23:24 +02:00
Align the plugin search example with the recommended registration pattern used in the general search documentation and NetBox core. Replace the legacy `indexes = [...]` example with decorator-based registration to make the preferred approach clearer for plugin authors.
1.1 KiB
1.1 KiB
Search
Plugins can define and register their own models to extend NetBox's core search functionality. Typically, a plugin will include a file named search.py, which holds all search indexes for its models.
# search.py
from netbox.search import SearchIndex, register_search
from .models import MyModel
@register_search
class MyModelIndex(SearchIndex):
model = MyModel
fields = (
('name', 100),
('description', 500),
('comments', 5000),
)
display_attrs = ('site', 'device', 'status', 'description')
Decorate each SearchIndex subclass with @register_search to register it with NetBox. When using the default search.py module, no additional indexes = [...] list is required.
Fields listed in display_attrs are not cached for matching, but they are displayed alongside the object in global search results to provide additional context.
!!! tip
The legacy indexes = [...] list remains supported via PluginConfig.search_indexes for backward compatibility and custom loading patterns.
::: netbox.search.SearchIndex