Commits

Owen Nelson committed 90339a2

until I can figure out how to make unsigned 64 bit (big)int fields in all db types, I am storing ips as varchar(39). Updated tests to work with transactional dbs like postgres.

  • Participants
  • Parent commits 09111ed

Comments (0)

Files changed (3)

File ipyfield/__init__.py

 __version__ = '0.1.4'
 
-import IPy
+#import IPy
 
 
-class IP(IPy.IP):
-    """
-    Wrap IPy.IP to prevent AttributeError getting raised while comparing IP
-    instances to non-IP instances.
-    """
-    def __cmp__(self, other):
-        if not isinstance(other, IPy.IPint):
-            return -2
-        return super(IP, self).__cmp__(other)
+#class IP(IPy.IP):
+#    """
+#    Wrap IPy.IP to prevent AttributeError getting raised while comparing IP
+#    instances to non-IP instances.
+#    """
+#    def __cmp__(self, other):
+#        if not isinstance(other, IPy.IPint):
+#            return -2
+#        return super(IP, self).__cmp__(other)
+#
 

File ipyfield/models.py

 from django.db import models
-from ipyfield import IP
+from IPy import IP
 
 
 class IPyField(models.Field):
         value = self.to_python(value)
         if not value:
             return None
-        return value.int()
+        return str(value.int())
 
     def to_string(self, obj):
         value = self._get_val_from_obj(obj)
         else:
             raise TypeError('Lookup type %r not supported.' % lookup_type)
 
+    def db_type(self):
+        return 'varchar(39)'
+
     def get_internal_type(self):
-        return 'BigIntegerField'
+        return 'CharField'
 

File ipyfield/tests.py

 from django.test import TestCase
 from django.db.models import Model
-from django.db import IntegrityError
+from django.db import IntegrityError, transaction
 from ipyfield.models import IPyField
-from ipyfield import IP
 import IPy
+from IPy import IP
 
 
 class DummyModel(Model):
         with self.assertRaises(IntegrityError):
             # non-null field should require value
             DummyModel.objects.create()
-        # null field is fine unspecified
-        DummyModel.objects.create(field='1.1.1.1')
 
     def test_ipv6_support(self):
         obj = DummyModel.objects.create(field='2001:dead:beef::1')