Skip to content

Commit

Permalink
Merge pull request #76 from jpic/master
Browse files Browse the repository at this point in the history
Support filter(*args)
  • Loading branch information
clokep authored Nov 26, 2020
2 parents f16d825 + e0c3a80 commit 6f2606c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
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

0 comments on commit 6f2606c

Please sign in to comment.