Просмотр исходного кода

Fixes #5331: Fix filtering of sites by null region

Jeremy Stretch 5 лет назад
Родитель
Сommit
bf836d4d46

+ 1 - 0
docs/release-notes/version-2.9.md

@@ -12,6 +12,7 @@
 * [#5271](https://github.com/netbox-community/netbox/issues/5271) - Fix auto-population of region field when editing a device
 * [#5314](https://github.com/netbox-community/netbox/issues/5314) - Fix config context rendering when multiple tags are assigned to an object
 * [#5324](https://github.com/netbox-community/netbox/issues/5324) - Add missing template extension tags for plugins for VM interface view
+* [#5331](https://github.com/netbox-community/netbox/issues/5331) - Fix filtering of sites by null region
 
 
 ---

+ 2 - 3
netbox/utilities/filters.py

@@ -68,11 +68,10 @@ class TreeNodeMultipleChoiceFilter(django_filters.ModelMultipleChoiceFilter):
     """
     Filters for a set of Models, including all descendant models within a Tree.  Example: [<Region: R1>,<Region: R2>]
     """
-
     def get_filter_predicate(self, v):
-        # null value filtering
+        # Null value filtering
         if v is None:
-            return {self.field_name.replace('in', 'isnull'): True}
+            return {f"{self.field_name}__isnull": True}
         return super().get_filter_predicate(v)
 
     def filter(self, qs, value):

+ 2 - 1
netbox/utilities/tests/test_filters.py

@@ -23,7 +23,8 @@ class TreeNodeMultipleChoiceFilterTest(TestCase):
     class SiteFilterSet(django_filters.FilterSet):
         region = TreeNodeMultipleChoiceFilter(
             queryset=Region.objects.all(),
-            field_name='region__in',
+            field_name='region',
+            lookup_expr='in',
             to_field_name='slug',
         )