1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

32 lines
1.1 KiB
Markdown
Raw Permalink Normal View History

# 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 (see the example below).
```python
# search.py
2022-10-21 13:16:16 -04:00
from netbox.search import SearchIndex
from .models import MyModel
2022-10-21 13:16:16 -04:00
class MyModelIndex(SearchIndex):
model = MyModel
2022-10-21 13:16:16 -04:00
fields = (
('name', 100),
('description', 500),
('comments', 5000),
)
display_attrs = ('site', 'device', 'status', 'description')
```
Fields listed in `display_attrs` will not be cached for search, but will be displayed alongside the object when it appears in global search results. This is helpful for conveying to the user additional information about an object.
To register one or more indexes with NetBox, define a list named `indexes` at the end of this file:
```python
indexes = [MyModelIndex]
```
!!! tip
The path to the list of search indexes can be modified by setting `search_indexes` in the PluginConfig instance.
::: netbox.search.SearchIndex