Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[soc2010/query-refactor] Implemented slicing, also found a bug in Mon…

…goDB/PyMongo.

git-svn-id: http://code.djangoproject.com/svn/django/branches/soc2010/query-refactor@13371 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 28c9044ee12414d8faf1a7e977ed0ec0745c4685 1 parent 6c6dc8f
@alex alex authored
View
5 django/contrib/mongodb/compiler.py
@@ -63,7 +63,6 @@ def build_query(self, aggregates=False):
assert not self.query.distinct
assert not self.query.extra
assert not self.query.having
- assert self.query.high_mark is None
filters = self.get_filters(self.query.where)
cursor = self.connection.db[self.query.model._meta.db_table].find(filters)
@@ -72,6 +71,10 @@ def build_query(self, aggregates=False):
(ordering.lstrip("-"), DESCENDING if ordering.startswith("-") else ASCENDING)
for ordering in self.query.order_by
])
+ if self.query.low_mark:
+ cursor = cursor.skip(self.query.low_mark)
+ if self.query.high_mark is not None:
+ cursor = cursor.limit(self.query.high_mark - self.query.low_mark)
return cursor
def results_iter(self):
View
29 tests/regressiontests/mongodb/tests.py
@@ -85,8 +85,35 @@ def test_orderby(self):
],
lambda g: g.name,
)
-
+ def test_slicing(self):
+ artists = [
+ Artist.objects.create(name="Huey Lewis"),
+ Artist.objects.create(name="John Hiatt"),
+ Artist.objects.create(name="Jackson Browne"),
+ Artist.objects.create(name="Rick Springfield"),
+ ]
+
+ for i in xrange(5):
+ # TODO: should be i, but Mongo falls over with limit(0)
+ for j in xrange(i+1, 5):
+ self.assertQuerysetEqual(
+ Artist.objects.all()[i:j],
+ artists[i:j],
+ lambda a: a,
+ )
+ self.assertQuerysetEqual(
+ Artist.objects.all()[:3],
+ artists[:3],
+ lambda a: a,
+ )
+
+ self.assertQuerysetEqual(
+ Artist.objects.all()[2:],
+ artists[2:],
+ lambda a: a,
+ )
+
def test_not_equals(self):
q = Group.objects.create(name="Queen", year_formed=1971)
e = Group.objects.create(name="The E Street Band", year_formed=1972)
Please sign in to comment.
Something went wrong with that request. Please try again.