2
0
Эх сурвалжийг харах

Fixes #7089 - Adds Q filter to ContentTypeFilterSet

Daniel Sheppard 4 жил өмнө
parent
commit
86da6c6c14

+ 1 - 0
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
 
 ---

+ 12 - 0
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