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.
This commit is contained in:
parent
74c025d028
commit
306d34873c
|
@ -1047,13 +1047,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"
|
||||
|
|
|
@ -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.
|
|
@ -27,6 +27,7 @@ Final releases
|
|||
.. toctree::
|
||||
:maxdepth: 1
|
||||
|
||||
.. 1.4.2 (uncomment on release)
|
||||
1.4.1
|
||||
1.4
|
||||
|
||||
|
|
|
@ -91,6 +91,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)
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -12,7 +12,7 @@ from django.utils import six
|
|||
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)
|
||||
|
||||
from .imagefield import (ImageFieldTests, ImageFieldTwoDimensionsTests,
|
||||
TwoImageFieldTests, ImageFieldNoDimensionsTests,
|
||||
|
@ -64,6 +64,14 @@ class BasicFieldTests(test.TestCase):
|
|||
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)
|
||||
|
|
Loading…
Reference in New Issue