Skip to content

Commit 2947c9d

Browse files
committed
Fix filterset behavior on multiple negative conditions: added comment
1 parent 42fe33c commit 2947c9d

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

url_filter/backends/django.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,11 @@ def filter_by_specs(self, queryset):
9696

9797
if include:
9898
queryset = queryset.filter(**include)
99+
100+
# Plain queryset.exclude(**exclude) would cause exclusion of ALL
101+
# negative-matching objects. I.e. x!=1&y!=2 is equivalent
102+
# to "NOT (x = 1 AND y = 2)" SQL, which is not an intuitive behavior.
103+
# We chain .exclude to achieve "NOT (x = 1) AND NOT (y = 2)" instead.
99104
for lookup, value in exclude.items():
100105
queryset = queryset.exclude(**{lookup: value})
101106

0 commit comments

Comments
 (0)