Fixes #5331: Fix filtering of sites by null region

This commit is contained in:
Jeremy Stretch 2020-11-09 15:58:59 -05:00
parent c3f2cc7648
commit bf836d4d46
3 changed files with 5 additions and 4 deletions

View File

@ -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
---

View File

@ -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):

View File

@ -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',
)