Commits

Anonymous committed fc1197a

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

Comments (0)

Files changed (2)

django/contrib/mongodb/compiler.py

         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:
             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():

tests/regressiontests/mongodb/tests.py

         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)
         
             ],
             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
+        )
+