Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[soc2010/query-refactor] Implemented __lt lookups for MongoDB.

  • Loading branch information...
commit 72c6a434038862c90e91a2087fbc38e1c48038d9 1 parent d19cba9
Alex Gaynor alex authored
4 django/contrib/mongodb/compiler.py
View
@@ -25,7 +25,7 @@ def get_filters(self, where, correct=False):
return filters
def make_atom(self, lhs, lookup_type, value_annotation, params_or_value, negated):
- assert lookup_type in ["exact", "isnull"], lookup_type
+ assert lookup_type in ["exact", "isnull", "lt"], lookup_type
if hasattr(lhs, "process"):
lhs, params = lhs.process(lookup_type, params_or_value, self.connection)
else:
@@ -47,6 +47,8 @@ def make_atom(self, lhs, lookup_type, value_annotation, params_or_value, negated
if value_annotation == negated:
val = {"$not": val}
return column, val
+ elif lookup_type == "lt":
+ return column, {"$lt": params[0]}
def correct_filters(self, filters):
for k, v in filters.items():
28 tests/regressiontests/mongodb/tests.py
View
@@ -58,7 +58,7 @@ def test_foreignkey(self):
self.assertFalse(hasattr(b, "_current_group_cache"))
self.assertEqual(b.current_group, e)
- def test_lookup(self):
+ 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)
@@ -80,3 +80,29 @@ def test_lookup(self):
],
lambda g: g.name,
)
+
+ def test_less_than(self):
+ q = Group.objects.create(name="Queen", year_formed=1971)
+ e = Group.objects.create(name="The E Street Band", year_formed=1972)
+
+ self.assertQuerysetEqual(
+ Group.objects.filter(year_formed__lt=1980), [
+ "Queen",
+ "The E Street Band",
+ ],
+ lambda g: g.name
+ )
+
+ self.assertQuerysetEqual(
+ Group.objects.filter(year_formed__lt=1972), [
+ "Queen",
+ ],
+ lambda g: g.name
+ )
+
+ self.assertQuerysetEqual(
+ Group.objects.filter(year_formed__lt=1971),
+ [],
+ lambda g: g.name
+ )
+
Please sign in to comment.
Something went wrong with that request. Please try again.