Skip to content

Commit

Permalink
Merge pull request #54 from webrunners/master
Browse files Browse the repository at this point in the history
Fix #53
  • Loading branch information
miki725 authored Feb 25, 2018
2 parents 48314cb + 2947c9d commit 43a9efe
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions url_filter/backends/django.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,12 @@ def filter_by_specs(self, queryset):

if include:
queryset = queryset.filter(**include)
if exclude:
queryset = queryset.exclude(**exclude)

# Plain queryset.exclude(**exclude) would cause exclusion of ALL
# negative-matching objects. I.e. x!=1&y!=2 is equivalent
# to "NOT (x = 1 AND y = 2)" SQL, which is not an intuitive behavior.
# We chain .exclude to achieve "NOT (x = 1) AND NOT (y = 2)" instead.
for lookup, value in exclude.items():
queryset = queryset.exclude(**{lookup: value})

return queryset.distinct()

0 comments on commit 43a9efe

Please sign in to comment.