Owen Nelson avatar Owen Nelson committed 70d7881

locking in valid lookup types to in and exact

Comments (0)

Files changed (4)



-__version__ = '0.1.2'
+__version__ = '0.1.3'


             if isinstance(value, str):
                 value = IP(value)
             return [self.get_prep_value(v) for v in value]
-        else: 
+        elif lookup_type == 'exact':
             return self.get_prep_value(value)
+        else:
+            raise TypeError('Lookup type %r not supported.' % lookup_type)
     def get_internal_type(self):
         return 'BigIntegerField'


         obj = DummyModel.objects.create(field='2001:dead:beef::1')
         self.assertEqual(obj.field.version(), 6)
+    def test_valid_lookups(self):
+        with self.assertRaises(TypeError):
+            # it's possible people will forget this is not a char/text field.
+            DummyModel.objects.filter(field__startswith='127.0.0')
+        with self.assertRaises(TypeError):
+            # greater/less than should be rewritten as range queries.
+            DummyModel.objects.filter(field__gt=1000)
+        # all valid, but won't return anything....
+        DummyModel.objects.filter(field=1000)
+        DummyModel.objects.filter(field__exact='127.0.0')
+        DummyModel.objects.filter(field__in=[1,2,3])
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.