mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-19 09:53:34 -06:00
Fixes #5331: Fix filtering of sites by null region
This commit is contained in:
parent
c3f2cc7648
commit
bf836d4d46
@ -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
|
||||
|
||||
|
||||
---
|
||||
|
@ -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):
|
||||
|
@ -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',
|
||||
)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user