Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed #16246 -- Fixed GenericIPAddressField tests on PostgreSQL.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@16395 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 823bac36db2e4679d03fdc36e318da779767cac6 1 parent 479f2bc
Jannis Leidel jezdez authored
7 django/db/models/fields/__init__.py
View
@@ -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 @@ def formfield(self, **kwargs):
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 @@ def to_python(self, value):
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:
4 django/forms/fields.py
View
@@ -965,8 +965,8 @@ def __init__(self, protocol='both', unpack_ipv4=False, *args, **kwargs):
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'])
6 tests/modeltests/validation/models.py
View
@@ -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)
Please sign in to comment.
Something went wrong with that request. Please try again.