From 86da6c6c14181238140da3e8d8cdef1db8a6a3a9 Mon Sep 17 00:00:00 2001 From: Daniel Sheppard Date: Tue, 31 Aug 2021 11:31:40 -0500 Subject: [PATCH] Fixes #7089 - Adds Q filter to ContentTypeFilterSet --- docs/release-notes/version-3.0.md | 1 + netbox/extras/filtersets.py | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/docs/release-notes/version-3.0.md b/docs/release-notes/version-3.0.md index 4de00d9ab..eb0cb948f 100644 --- a/docs/release-notes/version-3.0.md +++ b/docs/release-notes/version-3.0.md @@ -11,6 +11,7 @@ * [#7082](https://github.com/netbox-community/netbox/issues/7082) - Avoid exception when referencing invalid content type in table * [#7083](https://github.com/netbox-community/netbox/issues/7083) - Correct labeling for VM memory attribute * [#7084](https://github.com/netbox-community/netbox/issues/7084) - Fix KeyError exception when editing access VLAN on an interface +* [#7089](https://github.com/netbox-community/netbox/issues/7089) - Fix ContentTypeFilterSet not filtering on q filter * [#7096](https://github.com/netbox-community/netbox/issues/7096) - Home links should honor `BASE_PATH` configuration --- diff --git a/netbox/extras/filtersets.py b/netbox/extras/filtersets.py index 2a6ae088c..b827e5289 100644 --- a/netbox/extras/filtersets.py +++ b/netbox/extras/filtersets.py @@ -367,6 +367,18 @@ class JobResultFilterSet(BaseFilterSet): # class ContentTypeFilterSet(django_filters.FilterSet): + q = django_filters.CharFilter( + method='search', + label='Search', + ) + + def search(self, queryset, name, value): + if not value.strip(): + return queryset + return queryset.filter( + Q(app_label__icontains=value) | + Q(model__icontains=value) + ) class Meta: model = ContentType