mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-24 16:26:09 -06:00
8927 add docs
This commit is contained in:
parent
06164b5d1a
commit
777e883c73
31
docs/plugins/development/search.md
Normal file
31
docs/plugins/development/search.md
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
# Search
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
As an example, lets define a search_index for the MyModel object defined before:
|
||||||
|
|
||||||
|
```python
|
||||||
|
# search_indexes.py
|
||||||
|
from .filters import MyFilterSet
|
||||||
|
from .tables import MyModelTable
|
||||||
|
from .models import MyModel
|
||||||
|
from search.models import SearchMixin
|
||||||
|
|
||||||
|
|
||||||
|
class MyModelIndex(SearchMixin):
|
||||||
|
model = MyModel
|
||||||
|
queryset = MyModel.objects.all()
|
||||||
|
filterset = MyModelFilterSet
|
||||||
|
table = MyModelTable
|
||||||
|
url = 'plugins:netbox_mymodel:mymodel_list'
|
||||||
|
choice_header = 'MyModel'
|
||||||
|
```
|
||||||
|
|
||||||
|
All the fields must be defined as follows:
|
||||||
|
|
||||||
|
* `model` - The model that will be searched (see: [Models](./models.md)).
|
||||||
|
* `queryset` - The queryset on the model that will be passed to the filterset.
|
||||||
|
* `filterset` - The filterset for the model that contains the search method (see: [Filters & Filter Sets](./filtersets.md)).
|
||||||
|
* `table` - Table that is used in the list view (see: (see: [Tables](./tables.md)).
|
||||||
|
* `url` - URL to the list view to show search results.
|
||||||
|
* `choice_header` - The header that will appear in the search drop-down to group menu items together.
|
@ -132,6 +132,7 @@ nav:
|
|||||||
- GraphQL API: 'plugins/development/graphql-api.md'
|
- GraphQL API: 'plugins/development/graphql-api.md'
|
||||||
- Background Tasks: 'plugins/development/background-tasks.md'
|
- Background Tasks: 'plugins/development/background-tasks.md'
|
||||||
- Exceptions: 'plugins/development/exceptions.md'
|
- Exceptions: 'plugins/development/exceptions.md'
|
||||||
|
- Search: 'plugins/development/search.md'
|
||||||
- Administration:
|
- Administration:
|
||||||
- Authentication:
|
- Authentication:
|
||||||
- Overview: 'administration/authentication/overview.md'
|
- Overview: 'administration/authentication/overview.md'
|
||||||
|
Loading…
Reference in New Issue
Block a user