Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[1.4.x] Fixed #18212 -- Standardized arguments of GenericIPAddressField

Unlike other model fields, the newly introduced (1.4)
GenericIPAddressField did not accept verbose_name and name as the
first positional arguments. This commit fixes it.
Thanks Dan McGee for the report and the patch.

Backport of 306d348 from master.
  • Loading branch information...
commit 92f7af3c36ec62e0b55c69ae8e359e53c8cfec15 1 parent c2f1aa5
@claudep claudep authored
View
5 django/db/models/fields/__init__.py
@@ -1023,13 +1023,14 @@ class GenericIPAddressField(Field):
description = _("IP address")
default_error_messages = {}
- def __init__(self, protocol='both', unpack_ipv4=False, *args, **kwargs):
+ def __init__(self, verbose_name=None, name=None, protocol='both',
+ unpack_ipv4=False, *args, **kwargs):
self.unpack_ipv4 = unpack_ipv4
self.default_validators, invalid_error_message = \
validators.ip_address_validators(protocol, unpack_ipv4)
self.default_error_messages['invalid'] = invalid_error_message
kwargs['max_length'] = 39
- Field.__init__(self, *args, **kwargs)
+ Field.__init__(self, verbose_name, name, *args, **kwargs)
def get_internal_type(self):
return "GenericIPAddressField"
View
14 docs/releases/1.4.2.txt
@@ -0,0 +1,14 @@
+==========================
+Django 1.4.2 release notes
+==========================
+
+*TO BE RELEASED*
+
+This is the second security release in the Django 1.4 series.
+
+Backwards incompatible changes
+==============================
+
+* The newly introduced :class:`~django.db.models.GenericIPAddressField`
+ constructor arguments have been adapted to match those of all other model
+ fields. The first two keyword arguments are now verbose_name and name.
View
1  docs/releases/index.txt
@@ -20,6 +20,7 @@ Final releases
.. toctree::
:maxdepth: 1
+ .. 1.4.2 (uncomment on release)
1.4.1
1.4
View
4 tests/modeltests/validation/models.py
@@ -88,6 +88,8 @@ class GenericIPAddressTestModel(models.Model):
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")
+ ip_verbose_name = models.GenericIPAddressField("IP Address Verbose",
+ blank=True, null=True)
class GenericIPAddrUnpackUniqueTest(models.Model):
generic_v4unpack_ip = models.GenericIPAddressField(blank=True, unique=True, unpack_ipv4=True)
@@ -102,4 +104,4 @@ class MultipleAutoFields(models.Model):
auto2 = models.AutoField(primary_key=True)
except AssertionError, assertion_error:
pass # Fail silently
-assert str(assertion_error) == u"A model can't have more than one AutoField."
+assert str(assertion_error) == u"A model can't have more than one AutoField."
View
27 tests/regressiontests/model_fields/models.py
@@ -69,6 +69,33 @@ class BooleanModel(models.Model):
class RenamedField(models.Model):
modelname = models.IntegerField(name="fieldname", choices=((1,'One'),))
+class VerboseNameField(models.Model):
+ id = models.AutoField("verbose pk", primary_key=True)
+ field1 = models.BigIntegerField("verbose field1")
+ field2 = models.BooleanField("verbose field2")
+ field3 = models.CharField("verbose field3", max_length=10)
+ field4 = models.CommaSeparatedIntegerField("verbose field4", max_length=99)
+ field5 = models.DateField("verbose field5")
+ field6 = models.DateTimeField("verbose field6")
+ field7 = models.DecimalField("verbose field7", max_digits=6, decimal_places=1)
+ field8 = models.EmailField("verbose field8")
+ field9 = models.FileField("verbose field9", upload_to="unused")
+ field10 = models.FilePathField("verbose field10")
+ field11 = models.FloatField("verbose field11")
+ # Don't want to depend on PIL in this test
+ #field_image = models.ImageField("verbose field")
+ field12 = models.IntegerField("verbose field12")
+ field13 = models.IPAddressField("verbose field13")
+ field14 = models.GenericIPAddressField("verbose field14", protocol="ipv4")
+ field15 = models.NullBooleanField("verbose field15")
+ field16 = models.PositiveIntegerField("verbose field16")
+ field17 = models.PositiveSmallIntegerField("verbose field17")
+ field18 = models.SlugField("verbose field18")
+ field19 = models.SmallIntegerField("verbose field19")
+ field20 = models.TextField("verbose field20")
+ field21 = models.TimeField("verbose field21")
+ field22 = models.URLField("verbose field22")
+
# This model isn't used in any test, just here to ensure it validates successfully.
# See ticket #16570.
class DecimalLessThanOne(models.Model):
View
10 tests/regressiontests/model_fields/tests.py
@@ -11,7 +11,7 @@
from django.utils import unittest
from .models import (Foo, Bar, Whiz, BigD, BigS, Image, BigInt, Post,
- NullBooleanModel, BooleanModel, Document, RenamedField)
+ NullBooleanModel, BooleanModel, Document, RenamedField, VerboseNameField)
# If PIL available, do these tests.
if Image:
@@ -65,6 +65,14 @@ def test_field_name(self):
self.assertTrue(hasattr(instance, 'get_fieldname_display'))
self.assertFalse(hasattr(instance, 'get_modelname_display'))
+ def test_field_verbose_name(self):
+ m = VerboseNameField
+ for i in range(1, 23):
+ self.assertEqual(m._meta.get_field('field%d' % i).verbose_name,
+ 'verbose field%d' % i)
+
+ self.assertEqual(m._meta.get_field('id').verbose_name, 'verbose pk')
+
class DecimalFieldTests(test.TestCase):
def test_to_python(self):
f = models.DecimalField(max_digits=4, decimal_places=2)

0 comments on commit 92f7af3

Please sign in to comment.
Something went wrong with that request. Please try again.