mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
8927 plugin search (#10489)
* #7016 base search classes * 7016 add search indexes * 7016 add search indexes * 7016 add search indexes * 7016 add search indexes * 7016 add search indexes * 7016 add search indexes * 8927 refactor search * 8927 refactor search * 8927 refactor search * 8927 refactor search * 8927 get search choices working * 8927 cleanup - optimize * 8927 use backend search function * 8927 fix for plugin search * 8927 add docs * Move search app to a module under netbox/ * Utilize global registry to register model search classes * Build search form options from registry * Determine search categories from model app by default * Enable dynamic search registration for plugins * Update docs & improve plugin support * Clean up search backend class * Docs for #8927 Co-authored-by: jeremystretch <jstretch@ns1.com>
This commit is contained in:
@ -108,6 +108,7 @@ NetBox looks for the `config` variable within a plugin's `__init__.py` to load i
|
||||
| `max_version` | Maximum version of NetBox with which the plugin is compatible |
|
||||
| `middleware` | A list of middleware classes to append after NetBox's build-in middleware |
|
||||
| `queues` | A list of custom background task queues to create |
|
||||
| `search_extensions` | The dotted path to the list of search index classes (default: `search.indexes`) |
|
||||
| `template_extensions` | The dotted path to the list of template extension classes (default: `template_content.template_extensions`) |
|
||||
| `menu_items` | The dotted path to the list of menu items provided by the plugin (default: `navigation.menu_items`) |
|
||||
| `graphql_schema` | The dotted path to the plugin's GraphQL schema class, if any (default: `graphql.schema`) |
|
||||
|
29
docs/plugins/development/search.md
Normal file
29
docs/plugins/development/search.md
Normal file
@ -0,0 +1,29 @@
|
||||
# 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
|
||||
from netbox.search import SearchMixin
|
||||
from .filters import MyModelFilterSet
|
||||
from .tables import MyModelTable
|
||||
from .models import MyModel
|
||||
|
||||
class MyModelIndex(SearchMixin):
|
||||
model = MyModel
|
||||
queryset = MyModel.objects.all()
|
||||
filterset = MyModelFilterSet
|
||||
table = MyModelTable
|
||||
url = 'plugins:myplugin:mymodel_list'
|
||||
```
|
||||
|
||||
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
|
Reference in New Issue
Block a user