Refs #23801 -- Made integer field max_length warning show correct field type.
This commit is contained in:
parent
856ba1ec86
commit
c512912463
|
@ -1773,7 +1773,7 @@ class IntegerField(Field):
|
||||||
if self.max_length is not None:
|
if self.max_length is not None:
|
||||||
return [
|
return [
|
||||||
checks.Warning(
|
checks.Warning(
|
||||||
"'max_length' is ignored when used with IntegerField",
|
"'max_length' is ignored when used with %s." % self.__class__.__name__,
|
||||||
hint="Remove 'max_length' from field",
|
hint="Remove 'max_length' from field",
|
||||||
obj=self,
|
obj=self,
|
||||||
id='fields.W122',
|
id='fields.W122',
|
||||||
|
|
|
@ -143,7 +143,8 @@ Model fields
|
||||||
appeared before support for null values was added in Django 2.1.*
|
appeared before support for null values was added in Django 2.1.*
|
||||||
* **fields.E120**: ``CharField``\s must define a ``max_length`` attribute.
|
* **fields.E120**: ``CharField``\s must define a ``max_length`` attribute.
|
||||||
* **fields.E121**: ``max_length`` must be a positive integer.
|
* **fields.E121**: ``max_length`` must be a positive integer.
|
||||||
* **fields.W122**: ``max_length`` is ignored when used with ``IntegerField``.
|
* **fields.W122**: ``max_length`` is ignored when used with
|
||||||
|
``<integer field type>``.
|
||||||
* **fields.E130**: ``DecimalField``\s must define a ``decimal_places`` attribute.
|
* **fields.E130**: ``DecimalField``\s must define a ``decimal_places`` attribute.
|
||||||
* **fields.E131**: ``decimal_places`` must be a non-negative integer.
|
* **fields.E131**: ``decimal_places`` must be a non-negative integer.
|
||||||
* **fields.E132**: ``DecimalField``\s must define a ``max_digits`` attribute.
|
* **fields.E132**: ``DecimalField``\s must define a ``max_digits`` attribute.
|
||||||
|
|
|
@ -617,12 +617,19 @@ class IntegerFieldTests(SimpleTestCase):
|
||||||
|
|
||||||
def test_max_length_warning(self):
|
def test_max_length_warning(self):
|
||||||
class Model(models.Model):
|
class Model(models.Model):
|
||||||
value = models.IntegerField(max_length=2)
|
integer = models.IntegerField(max_length=2)
|
||||||
|
biginteger = models.BigIntegerField(max_length=2)
|
||||||
|
smallinteger = models.SmallIntegerField(max_length=2)
|
||||||
|
positiveinteger = models.PositiveIntegerField(max_length=2)
|
||||||
|
positivesmallinteger = models.PositiveSmallIntegerField(max_length=2)
|
||||||
|
|
||||||
field = Model._meta.get_field('value')
|
for field in Model._meta.get_fields():
|
||||||
|
if field.auto_created:
|
||||||
|
continue
|
||||||
|
with self.subTest(name=field.name):
|
||||||
self.assertEqual(field.check(), [
|
self.assertEqual(field.check(), [
|
||||||
DjangoWarning(
|
DjangoWarning(
|
||||||
"'max_length' is ignored when used with IntegerField",
|
"'max_length' is ignored when used with %s." % field.__class__.__name__,
|
||||||
hint="Remove 'max_length' from field",
|
hint="Remove 'max_length' from field",
|
||||||
obj=field,
|
obj=field,
|
||||||
id='fields.W122',
|
id='fields.W122',
|
||||||
|
|
Loading…
Reference in New Issue