fix chaining of the limit, skip, hint, and batch_size
This commit is contained in:
parent
bad4e6846a
commit
6ac7a8eec6
@ -759,7 +759,10 @@ class BaseQuerySet(object):
|
|||||||
queryset = self.clone()
|
queryset = self.clone()
|
||||||
queryset._limit = n if n != 0 else 1
|
queryset._limit = n if n != 0 else 1
|
||||||
|
|
||||||
# Return the new queryset to allow chaining
|
# If a cursor object has already been created, apply the limit to it.
|
||||||
|
if queryset._cursor_obj:
|
||||||
|
queryset._cursor_obj.limit(queryset._limit)
|
||||||
|
|
||||||
return queryset
|
return queryset
|
||||||
|
|
||||||
def skip(self, n):
|
def skip(self, n):
|
||||||
@ -770,6 +773,11 @@ class BaseQuerySet(object):
|
|||||||
"""
|
"""
|
||||||
queryset = self.clone()
|
queryset = self.clone()
|
||||||
queryset._skip = n
|
queryset._skip = n
|
||||||
|
|
||||||
|
# If a cursor object has already been created, apply the skip to it.
|
||||||
|
if queryset._cursor_obj:
|
||||||
|
queryset._cursor_obj.skip(queryset._skip)
|
||||||
|
|
||||||
return queryset
|
return queryset
|
||||||
|
|
||||||
def hint(self, index=None):
|
def hint(self, index=None):
|
||||||
@ -787,6 +795,11 @@ class BaseQuerySet(object):
|
|||||||
"""
|
"""
|
||||||
queryset = self.clone()
|
queryset = self.clone()
|
||||||
queryset._hint = index
|
queryset._hint = index
|
||||||
|
|
||||||
|
# If a cursor object has already been created, apply the hint to it.
|
||||||
|
if queryset._cursor_obj:
|
||||||
|
queryset._cursor_obj.hint(queryset._hint)
|
||||||
|
|
||||||
return queryset
|
return queryset
|
||||||
|
|
||||||
def batch_size(self, size):
|
def batch_size(self, size):
|
||||||
@ -800,6 +813,11 @@ class BaseQuerySet(object):
|
|||||||
"""
|
"""
|
||||||
queryset = self.clone()
|
queryset = self.clone()
|
||||||
queryset._batch_size = size
|
queryset._batch_size = size
|
||||||
|
|
||||||
|
# If a cursor object has already been created, apply the batch size to it.
|
||||||
|
if queryset._cursor_obj:
|
||||||
|
queryset._cursor_obj.batch_size(queryset._batch_size)
|
||||||
|
|
||||||
return queryset
|
return queryset
|
||||||
|
|
||||||
def distinct(self, field):
|
def distinct(self, field):
|
||||||
|
@ -171,8 +171,9 @@ class QuerySetTest(unittest.TestCase):
|
|||||||
# Test slice limit and skip on an existing queryset
|
# Test slice limit and skip on an existing queryset
|
||||||
people = self.Person.objects
|
people = self.Person.objects
|
||||||
self.assertEqual(len(people), 3)
|
self.assertEqual(len(people), 3)
|
||||||
self.assertEqual(people[1:2], 1)
|
people2 = people[1:2]
|
||||||
self.assertEqual(people[0].name, 'User B')
|
self.assertEqual(len(people2), 1)
|
||||||
|
self.assertEqual(people2[0].name, 'User B')
|
||||||
|
|
||||||
# Test slice limit and skip cursor reset
|
# Test slice limit and skip cursor reset
|
||||||
qs = self.Person.objects[1:2]
|
qs = self.Person.objects[1:2]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user