diff --git a/docs/plugins/development/search.md b/docs/plugins/development/search.md new file mode 100644 index 000000000..73d515485 --- /dev/null +++ b/docs/plugins/development/search.md @@ -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. diff --git a/mkdocs.yml b/mkdocs.yml index 4e2cb73dd..a7977d7ea 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -132,6 +132,7 @@ nav: - GraphQL API: 'plugins/development/graphql-api.md' - Background Tasks: 'plugins/development/background-tasks.md' - Exceptions: 'plugins/development/exceptions.md' + - Search: 'plugins/development/search.md' - Administration: - Authentication: - Overview: 'administration/authentication/overview.md'