Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions docs/plugins/development/filtersets.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,27 @@ class MyModelViewSet(...):
filterset_class = filtersets.MyModelFilterSet
```

### Implementing Quick Search

The `ObjectListView` has a field called Quick Search. For Quick Search to work the corresponding FilterSet has to override the `search` method that is implemented in `NetBoxModelFilterSet`. This function takes a queryset and can perform arbitrary operations on it and return it. A common use-case is to search for the given search value in multiple fields:

```python
from django.db.models import Q
from netbox.filtersets import NetBoxModelFilterSet

class MyFilterSet(NetBoxModelFilterSet):
...
def search(self, queryset, name, value):
if not value.strip():
return queryset
return queryset.filter(
Q(name__icontains=value) |
Q(description__icontains=value)
)
```

The `search` method is also used by the `q` filter in `NetBoxModelFilterSet` which in turn is used by the Search field in the filters tab.

## Filter Classes

### TagFilter
Expand Down