mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-25 18:08:38 -06:00
added lookup map for treenode filter
This commit is contained in:
parent
c908f132ec
commit
e5f8f15293
@ -57,6 +57,10 @@ FILTER_NEGATION_LOOKUP_MAP = dict(
|
|||||||
n='exact'
|
n='exact'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
FILTER_TREENODE_NEGATION_LOOKUP_MAP = dict(
|
||||||
|
n='in'
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
# Keys for PostgreSQL advisory locks. These are arbitrary bigints used by
|
# Keys for PostgreSQL advisory locks. These are arbitrary bigints used by
|
||||||
# the advisory_lock contextmanager. When a lock is acquired,
|
# the advisory_lock contextmanager. When a lock is acquired,
|
||||||
|
@ -8,7 +8,8 @@ from django_filters.utils import get_model_field, resolve_field
|
|||||||
|
|
||||||
from extras.models import Tag
|
from extras.models import Tag
|
||||||
from utilities.constants import (
|
from utilities.constants import (
|
||||||
FILTER_CHAR_BASED_LOOKUP_MAP, FILTER_NEGATION_LOOKUP_MAP, FILTER_NUMERIC_BASED_LOOKUP_MAP
|
FILTER_CHAR_BASED_LOOKUP_MAP, FILTER_NEGATION_LOOKUP_MAP, FILTER_TREENODE_NEGATION_LOOKUP_MAP,
|
||||||
|
FILTER_NUMERIC_BASED_LOOKUP_MAP
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -181,10 +182,15 @@ class BaseFilterSet(django_filters.FilterSet):
|
|||||||
)):
|
)):
|
||||||
lookup_map = FILTER_NUMERIC_BASED_LOOKUP_MAP
|
lookup_map = FILTER_NUMERIC_BASED_LOOKUP_MAP
|
||||||
|
|
||||||
|
elif isinstance(existing_filter, (
|
||||||
|
TreeNodeMultipleChoiceFilter,
|
||||||
|
)):
|
||||||
|
# TreeNodeMultipleChoiceFilter only support negation but must maintain the `in` lookup expression
|
||||||
|
lookup_map = FILTER_TREENODE_NEGATION_LOOKUP_MAP
|
||||||
|
|
||||||
elif isinstance(existing_filter, (
|
elif isinstance(existing_filter, (
|
||||||
django_filters.ModelChoiceFilter,
|
django_filters.ModelChoiceFilter,
|
||||||
django_filters.ModelMultipleChoiceFilter,
|
django_filters.ModelMultipleChoiceFilter,
|
||||||
TreeNodeMultipleChoiceFilter,
|
|
||||||
TagFilter
|
TagFilter
|
||||||
)) or existing_filter.extra.get('choices'):
|
)) or existing_filter.extra.get('choices'):
|
||||||
# These filter types support only negation
|
# These filter types support only negation
|
||||||
@ -237,8 +243,6 @@ class BaseFilterSet(django_filters.FilterSet):
|
|||||||
# Create new filters for each lookup expression in the map
|
# Create new filters for each lookup expression in the map
|
||||||
for lookup_name, lookup_expr in lookup_map.items():
|
for lookup_name, lookup_expr in lookup_map.items():
|
||||||
new_filter_name = '{}__{}'.format(existing_filter_name, lookup_name)
|
new_filter_name = '{}__{}'.format(existing_filter_name, lookup_name)
|
||||||
if existing_filter.lookup_expr == 'in':
|
|
||||||
lookup_expr = 'in' # 'in' lookups must remain to avoid unwanted slicing on certain querysets
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if existing_filter_name in cls.declared_filters:
|
if existing_filter_name in cls.declared_filters:
|
||||||
|
Loading…
Reference in New Issue
Block a user