Commits

Owen Nelson committed 70d7881

locking in valid lookup types to in and exact

  • Participants
  • Parent commits 45830e2

Comments (0)

Files changed (4)

+^.idea
 ^.project$
 ^.pydevproject$
 ^.settings/

ipyfield/__init__.py

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

ipyfield/models.py

             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'

ipyfield/tests.py

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