Ticket #18212: generic_ip_verbose_name.patch
File generic_ip_verbose_name.patch, 4.8 KB (added by , 13 years ago) |
---|
-
tests/modeltests/validation/models.py
87 87 generic_ip = models.GenericIPAddressField(blank=True, null=True, unique=True) 88 88 v4_ip = models.GenericIPAddressField(blank=True, null=True, protocol="ipv4") 89 89 v6_ip = models.GenericIPAddressField(blank=True, null=True, protocol="ipv6") 90 ip_verbose_name = models.GenericIPAddressField("IP Address Verbose", 91 blank=True, null=True) 90 92 91 93 class GenericIPAddrUnpackUniqueTest(models.Model): 92 94 generic_v4unpack_ip = models.GenericIPAddressField(blank=True, unique=True, unpack_ipv4=True) -
tests/regressiontests/model_fields/tests.py
11 11 from django.utils import unittest 12 12 13 13 from .models import (Foo, Bar, Whiz, BigD, BigS, Image, BigInt, Post, 14 NullBooleanModel, BooleanModel, Document, RenamedField )14 NullBooleanModel, BooleanModel, Document, RenamedField, VerboseNameField) 15 15 16 16 # If PIL available, do these tests. 17 17 if Image: … … 65 65 self.assertTrue(hasattr(instance, 'get_fieldname_display')) 66 66 self.assertFalse(hasattr(instance, 'get_modelname_display')) 67 67 68 def test_field_verbose_name(self): 69 m = VerboseNameField 70 for i in range(1, 23): 71 self.assertEqual(m._meta.get_field('field%d' % i).verbose_name, 72 'verbose field%d' % i) 73 74 self.assertEqual(m._meta.get_field('id').verbose_name, 'verbose pk') 75 68 76 class DecimalFieldTests(test.TestCase): 69 77 def test_to_python(self): 70 78 f = models.DecimalField(max_digits=4, decimal_places=2) -
tests/regressiontests/model_fields/models.py
69 69 class RenamedField(models.Model): 70 70 modelname = models.IntegerField(name="fieldname", choices=((1,'One'),)) 71 71 72 class VerboseNameField(models.Model): 73 id = models.AutoField("verbose pk", primary_key=True) 74 field1 = models.BigIntegerField("verbose field1") 75 field2 = models.BooleanField("verbose field2") 76 field3 = models.CharField("verbose field3", max_length=10) 77 field4 = models.CommaSeparatedIntegerField("verbose field4", max_length=99) 78 field5 = models.DateField("verbose field5") 79 field6 = models.DateTimeField("verbose field6") 80 field7 = models.DecimalField("verbose field7", max_digits=6, decimal_places=1) 81 field8 = models.EmailField("verbose field8") 82 field9 = models.FileField("verbose field9", upload_to="unused") 83 field10 = models.FilePathField("verbose field10") 84 field11 = models.FloatField("verbose field11") 85 # Don't want to depend on PIL in this test 86 #field_image = models.ImageField("verbose field") 87 field12 = models.IntegerField("verbose field12") 88 field13 = models.IPAddressField("verbose field13") 89 field14 = models.GenericIPAddressField("verbose field14", protocol="ipv4") 90 field15 = models.NullBooleanField("verbose field15") 91 field16 = models.PositiveIntegerField("verbose field16") 92 field17 = models.PositiveSmallIntegerField("verbose field17") 93 field18 = models.SlugField("verbose field18") 94 field19 = models.SmallIntegerField("verbose field19") 95 field20 = models.TextField("verbose field20") 96 field21 = models.TimeField("verbose field21") 97 field22 = models.URLField("verbose field22") 98 72 99 # This model isn't used in any test, just here to ensure it validates successfully. 73 100 # See ticket #16570. 74 101 class DecimalLessThanOne(models.Model): -
django/db/models/fields/__init__.py
1035 1035 description = _("IP address") 1036 1036 default_error_messages = {} 1037 1037 1038 def __init__(self, protocol='both', unpack_ipv4=False, *args, **kwargs): 1038 def __init__(self, verbose_name=None, name=None, protocol='both', 1039 unpack_ipv4=False, *args, **kwargs): 1039 1040 self.unpack_ipv4 = unpack_ipv4 1040 1041 self.default_validators, invalid_error_message = \ 1041 1042 validators.ip_address_validators(protocol, unpack_ipv4) 1042 1043 self.default_error_messages['invalid'] = invalid_error_message 1043 1044 kwargs['max_length'] = 39 1044 Field.__init__(self, *args, **kwargs)1045 Field.__init__(self, verbose_name, name, *args, **kwargs) 1045 1046 1046 1047 def get_internal_type(self): 1047 1048 return "GenericIPAddressField"