Skip to content

Commit d2db498

Browse files
committed
8927 add docs
1 parent 41773cd commit d2db498

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

docs/plugins/development/search.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Search
2+
3+
If you want your plugin models to appear in search results, you will need to create a search index for the models. Search indexes must be in defined in a search_indexes.py file.
4+
5+
As an example, lets define a search_index for the MyModel object defined before:
6+
7+
```python
8+
# search_indexes.py
9+
from .filters import MyFilterSet
10+
from .tables import MyModelTable
11+
from .models import MyModel
12+
from search.models import SearchMixin
13+
14+
15+
class MyModelIndex(SearchMixin):
16+
model = MyModel
17+
queryset = MyModel.objects.all()
18+
filterset = MyModelFilterSet
19+
table = MyModelTable
20+
url = 'plugins:netbox_mymodel:mymodel_list'
21+
choice_header = 'MyModel'
22+
```
23+
24+
All the fields must be defined as follows:
25+
26+
* `model` - The model that will be searched (see: [Models](./models.md)).
27+
* `queryset` - The queryset on the model that will be passed to the filterset.
28+
* `filterset` - The filterset for the model that contains the search method (see: [Filters & Filter Sets](./filtersets.md)).
29+
* `table` - Table that is used in the list view (see: (see: [Tables](./tables.md)).
30+
* `url` - URL to the list view to show search results.
31+
* `choice_header` - The header that will appear in the search drop-down to group menu items together.

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ nav:
133133
- GraphQL API: 'plugins/development/graphql-api.md'
134134
- Background Tasks: 'plugins/development/background-tasks.md'
135135
- Exceptions: 'plugins/development/exceptions.md'
136+
- Search: 'plugins/development/search.md'
136137
- Administration:
137138
- Authentication:
138139
- Overview: 'administration/authentication/overview.md'

0 commit comments

Comments
 (0)