mirror of
https://github.com/django/django.git
synced 2025-07-04 17:59:13 +00:00
[soc2010/query-refactor] Implemented __lt lookups for MongoDB.
git-svn-id: http://code.djangoproject.com/svn/django/branches/soc2010/query-refactor@13359 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
d19cba9b8c
commit
72c6a43403
@ -25,7 +25,7 @@ class SQLCompiler(object):
|
|||||||
return filters
|
return filters
|
||||||
|
|
||||||
def make_atom(self, lhs, lookup_type, value_annotation, params_or_value, negated):
|
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"):
|
if hasattr(lhs, "process"):
|
||||||
lhs, params = lhs.process(lookup_type, params_or_value, self.connection)
|
lhs, params = lhs.process(lookup_type, params_or_value, self.connection)
|
||||||
else:
|
else:
|
||||||
@ -47,6 +47,8 @@ class SQLCompiler(object):
|
|||||||
if value_annotation == negated:
|
if value_annotation == negated:
|
||||||
val = {"$not": val}
|
val = {"$not": val}
|
||||||
return column, val
|
return column, val
|
||||||
|
elif lookup_type == "lt":
|
||||||
|
return column, {"$lt": params[0]}
|
||||||
|
|
||||||
def correct_filters(self, filters):
|
def correct_filters(self, filters):
|
||||||
for k, v in filters.items():
|
for k, v in filters.items():
|
||||||
|
@ -58,7 +58,7 @@ class MongoTestCase(TestCase):
|
|||||||
self.assertFalse(hasattr(b, "_current_group_cache"))
|
self.assertFalse(hasattr(b, "_current_group_cache"))
|
||||||
self.assertEqual(b.current_group, e)
|
self.assertEqual(b.current_group, e)
|
||||||
|
|
||||||
def test_lookup(self):
|
def test_not_equals(self):
|
||||||
q = Group.objects.create(name="Queen", year_formed=1971)
|
q = Group.objects.create(name="Queen", year_formed=1971)
|
||||||
e = Group.objects.create(name="The E Street Band", year_formed=1972)
|
e = Group.objects.create(name="The E Street Band", year_formed=1972)
|
||||||
|
|
||||||
@ -80,3 +80,29 @@ class MongoTestCase(TestCase):
|
|||||||
],
|
],
|
||||||
lambda g: g.name,
|
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
|
||||||
|
)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user