Fixed #16246 -- Fixed GenericIPAddressField tests on PostgreSQL.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@16395 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Jannis Leidel 2011-06-13 20:15:13 +00:00
parent 479f2bce3c
commit 823bac36db
3 changed files with 12 additions and 5 deletions

View File

@ -910,6 +910,7 @@ class BigIntegerField(IntegerField):
empty_strings_allowed = False
description = _("Big (8 byte) integer")
MAX_BIGINT = 9223372036854775807
def get_internal_type(self):
return "BigIntegerField"
@ -922,6 +923,7 @@ class BigIntegerField(IntegerField):
class IPAddressField(Field):
empty_strings_allowed = False
description = _("IPv4 address")
def __init__(self, *args, **kwargs):
kwargs['max_length'] = 15
Field.__init__(self, *args, **kwargs)
@ -956,6 +958,11 @@ class GenericIPAddressField(Field):
self.unpack_ipv4, self.error_messages['invalid'])
return value
def get_db_prep_value(self, value, connection, prepared=False):
if not prepared:
value = self.get_prep_value(value)
return value or None
def get_prep_value(self, value):
if value and ':' in value:
try:

View File

@ -965,8 +965,8 @@ class GenericIPAddressField(CharField):
super(GenericIPAddressField, self).__init__(*args, **kwargs)
def to_python(self, value):
if not value:
return ''
if value in validators.EMPTY_VALUES:
return u''
if value and ':' in value:
return clean_ipv6_address(value,
self.unpack_ipv4, self.error_messages['invalid'])

View File

@ -84,9 +84,9 @@ class UniqueErrorsModel(models.Model):
number = models.IntegerField(unique=True, error_messages={'unique': u'Custom unique number message.'})
class GenericIPAddressTestModel(models.Model):
generic_ip = models.GenericIPAddressField(blank=True, unique=True)
v4_ip = models.GenericIPAddressField(blank=True, protocol="ipv4")
v6_ip = models.GenericIPAddressField(blank=True, protocol="ipv6")
generic_ip = models.GenericIPAddressField(blank=True, null=True, unique=True)
v4_ip = models.GenericIPAddressField(blank=True, null=True, protocol="ipv4")
v6_ip = models.GenericIPAddressField(blank=True, null=True, protocol="ipv6")
class GenericIPAddrUnpackUniqueTest(models.Model):
generic_v4unpack_ip = models.GenericIPAddressField(blank=True, unique=True, unpack_ipv4=True)