Author: Alex
Date: 2010-06-18 20:36:13 -0500 (Fri, 18 Jun 2010)
New Revision: 13359

Modified:
   django/branches/soc2010/query-refactor/django/contrib/mongodb/compiler.py
   django/branches/soc2010/query-refactor/tests/regressiontests/mongodb/tests.py
Log:
[soc2010/query-refactor] Implemented __lt lookups for MongoDB.

Modified: 
django/branches/soc2010/query-refactor/django/contrib/mongodb/compiler.py
===================================================================
--- django/branches/soc2010/query-refactor/django/contrib/mongodb/compiler.py   
2010-06-19 01:26:36 UTC (rev 13358)
+++ django/branches/soc2010/query-refactor/django/contrib/mongodb/compiler.py   
2010-06-19 01:36:13 UTC (rev 13359)
@@ -25,7 +25,7 @@
         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 @@
             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():

Modified: 
django/branches/soc2010/query-refactor/tests/regressiontests/mongodb/tests.py
===================================================================
--- 
django/branches/soc2010/query-refactor/tests/regressiontests/mongodb/tests.py   
    2010-06-19 01:26:36 UTC (rev 13358)
+++ 
django/branches/soc2010/query-refactor/tests/regressiontests/mongodb/tests.py   
    2010-06-19 01:36:13 UTC (rev 13359)
@@ -58,7 +58,7 @@
         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 @@
             ],
             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
+        )
+

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-upda...@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to