Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support filter(*args) #76

Merged
merged 1 commit into from
Nov 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions queryset_sequence/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -685,12 +685,12 @@ def _filter_or_exclude_querysets(self, negate, **kwargs):
self._querysets = [self._querysets[i] for i in self._queryset_idxs]

# Methods that return new QuerySets
def filter(self, **kwargs):
def filter(self, *args, **kwargs):
qss_fields, fields = self._separate_filter_fields(**kwargs)

clone = self._clone()
clone._filter_or_exclude_querysets(False, **qss_fields)
clone._querysets = [qs.filter(**fields) for qs in clone._querysets]
clone._querysets = [qs.filter(*args, **fields) for qs in clone._querysets]
return clone

def exclude(self, **kwargs):
Expand Down
13 changes: 12 additions & 1 deletion tests/test_querysetsequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
FieldError,
MultipleObjectsReturned,
ObjectDoesNotExist)
from django.db.models import Count
from django.db.models import Count, Q
from django.db.models.query import EmptyQuerySet
from django.test import TestCase

Expand Down Expand Up @@ -443,6 +443,17 @@ def test_filter_by_relation(self):
with self.assertNumQueries(2):
self.assertEqual(bob_qss.count(), 3)

def test_filter_args(self):
"""
Ensure that filter() properly filters the children QuerySets, even when
being passed args.
"""
# Filter to just Bob's work.
with self.assertNumQueries(0):
bob_qss = self.all.filter(Q(author=self.bob))
with self.assertNumQueries(2):
self.assertEqual(bob_qss.count(), 3)

def test_empty(self):
"""
Ensure that filter() works when it results in an empty QuerySet.
Expand Down