Skip to content
Open
Changes from 1 commit
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
22 changes: 22 additions & 0 deletions docs/plugins/development/filtersets.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,28 @@ class MyModelViewSet(...):
filterset_class = filtersets.MyModelFilterSet
```

### Search function for use by the ObjectListView quick search

The `ObjectListView` has a field called Quick Search.
For this field to work the corresponding FilterSet has to implement the `search` function.
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)
)
```

## Filter Classes

### TagFilter
Expand Down