Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Edited model check messages for grammar and consistency.

  • Loading branch information...
commit bc4dc6e99c532b844a26c8a9021a4d04703e28cd 1 parent f7587b2
Russell Keith-Magee freakboy3742 authored
12 django/contrib/contenttypes/fields.py
View
@@ -67,7 +67,7 @@ def _check_field_name(self):
'Field names must not end with an underscore.',
hint=None,
obj=self,
- id='contenttypes.E001',
+ id='fields.E001',
)
]
else:
@@ -82,7 +82,7 @@ def _check_object_id_field(self):
"The GenericForeignKey object ID references the non-existent field '%s'." % self.fk_field,
hint=None,
obj=self,
- id='contenttypes.E002',
+ id='contenttypes.E001',
)
]
else:
@@ -102,7 +102,7 @@ def _check_content_type_field(self):
),
hint=None,
obj=self,
- id='contenttypes.E003',
+ id='contenttypes.E002',
)
]
else:
@@ -114,7 +114,7 @@ def _check_content_type_field(self):
),
hint="GenericForeignKeys must use a ForeignKey to 'contenttypes.ContentType' as the 'content_type' field.",
obj=self,
- id='contenttypes.E004',
+ id='contenttypes.E003',
)
]
elif field.rel.to != ContentType:
@@ -125,7 +125,7 @@ def _check_content_type_field(self):
),
hint="GenericForeignKeys must use a ForeignKey to 'contenttypes.ContentType' as the 'content_type' field.",
obj=self,
- id='contenttypes.E005',
+ id='contenttypes.E004',
)
]
else:
@@ -282,7 +282,7 @@ def _check_generic_foreign_key_existence(self):
return []
else:
return [
- checks.Warning(
+ checks.Error(
("The GenericRelation defines a relation with the model "
"'%s.%s', but that model does not have a GenericForeignKey.") % (
target._meta.app_label, target._meta.object_name
98 django/db/models/base.py
View
@@ -1078,26 +1078,22 @@ def _check_swappable(cls):
except ValueError:
errors.append(
checks.Error(
- '"%s" is not of the form "app_label.app_name".' % cls._meta.swappable,
+ "'%s' is not of the form 'app_label.app_name'." % cls._meta.swappable,
hint=None,
- obj=cls,
- id='E002',
+ obj=None,
+ id='models.E001',
)
)
except LookupError:
app_label, model_name = cls._meta.swapped.split('.')
errors.append(
checks.Error(
- ('The model has been swapped out for %s.%s '
- 'which has not been installed or is abstract.') % (
- app_label, model_name
+ ("'%s' references '%s.%s', which has not been installed, or is abstract.") % (
+ cls._meta.swappable, app_label, model_name
),
- hint=('Ensure that you did not misspell the model '
- 'name and the app name as well as the model '
- 'is not abstract. Does your INSTALLED_APPS '
- 'setting contain the "%s" app?') % app_label,
- obj=cls,
- id='E003',
+ hint=None,
+ obj=None,
+ id='models.E002',
)
)
return errors
@@ -1144,13 +1140,14 @@ def _check_m2m_through_same_relationship(cls):
if signature in seen_intermediary_signatures:
errors.append(
checks.Error(
- ('The model has two many-to-many relations through '
- 'the intermediary %s model, which is not permitted.') % (
+ ("The model has two many-to-many relations through "
+ "the intermediate model '%s.%s'.") % (
+ f.rel.through._meta.app_label,
f.rel.through._meta.object_name
),
hint=None,
obj=cls,
- id='E004',
+ id='models.E003',
)
)
else:
@@ -1167,13 +1164,11 @@ def _check_id_field(cls):
if fields and not fields[0].primary_key and cls._meta.pk.name == 'id':
return [
checks.Error(
- ('You cannot use "id" as a field name, because each model '
- 'automatically gets an "id" field if none '
- 'of the fields have primary_key=True.'),
- hint=('Remove or rename "id" field '
- 'or add primary_key=True to a field.'),
+ ("'id' can only be used as a field name if the field also "
+ "sets 'primary_key=True'."),
+ hint=None,
obj=cls,
- id='E005',
+ id='models.E004',
)
]
else:
@@ -1193,15 +1188,15 @@ def _check_field_name_clashes(cls):
if clash:
errors.append(
checks.Error(
- ('The field "%s" from parent model '
- '%s clashes with the field "%s" '
- 'from parent model %s.') % (
+ ("The field '%s' from parent model "
+ "'%s' clashes with the field '%s' "
+ "from parent model '%s'.") % (
clash.name, clash.model._meta,
f.name, f.model._meta
),
hint=None,
obj=cls,
- id='E053',
+ id='models.E005',
)
)
used_fields[f.name] = f
@@ -1220,13 +1215,13 @@ def _check_field_name_clashes(cls):
if clash and not id_conflict:
errors.append(
checks.Error(
- ('The field clashes with the field "%s" '
- 'from model %s.') % (
- clash.name, clash.model._meta
+ ("The field '%s' clashes with the field '%s' "
+ "from model '%s'.") % (
+ f.name, clash.name, clash.model._meta
),
hint=None,
obj=f,
- id='E054',
+ id='models.E006',
)
)
used_fields[f.name] = f
@@ -1247,9 +1242,10 @@ def _check_column_name_clashes(cls):
if column_name and column_name in used_column_names:
errors.append(
checks.Error(
- 'Field "%s" has column name "%s" that is already used.' % (f.name, column_name),
- hint=None,
+ "Field '%s' has column name '%s' that is used by another field." % (f.name, column_name),
+ hint="Specify a 'db_column' for the field.",
obj=cls,
+ id='models.E007'
)
)
else:
@@ -1263,10 +1259,10 @@ def _check_index_together(cls):
if not isinstance(cls._meta.index_together, (tuple, list)):
return [
checks.Error(
- '"index_together" must be a list or tuple.',
+ "'index_together' must be a list or tuple.",
hint=None,
obj=cls,
- id='E006',
+ id='models.E008',
)
]
@@ -1274,10 +1270,10 @@ def _check_index_together(cls):
for fields in cls._meta.index_together):
return [
checks.Error(
- 'All "index_together" elements must be lists or tuples.',
+ "All 'index_together' elements must be lists or tuples.",
hint=None,
obj=cls,
- id='E007',
+ id='models.E009',
)
]
@@ -1293,10 +1289,10 @@ def _check_unique_together(cls):
if not isinstance(cls._meta.unique_together, (tuple, list)):
return [
checks.Error(
- '"unique_together" must be a list or tuple.',
+ "'unique_together' must be a list or tuple.",
hint=None,
obj=cls,
- id='E008',
+ id='models.E010',
)
]
@@ -1304,10 +1300,10 @@ def _check_unique_together(cls):
for fields in cls._meta.unique_together):
return [
checks.Error(
- 'All "unique_together" elements must be lists or tuples.',
+ "All 'unique_together' elements must be lists or tuples.",
hint=None,
obj=cls,
- id='E009',
+ id='models.E011',
)
]
@@ -1329,23 +1325,23 @@ def _check_local_fields(cls, fields, option):
except models.FieldDoesNotExist:
errors.append(
checks.Error(
- '"%s" points to a missing field named "%s".' % (option, field_name),
- hint='Ensure that you did not misspell the field name.',
+ "'%s' refers to the non-existent field '%s'." % (option, field_name),
+ hint=None,
obj=cls,
- id='E010',
+ id='models.E012',
)
)
else:
if isinstance(field.rel, models.ManyToManyRel):
errors.append(
checks.Error(
- ('"%s" refers to a m2m "%s" field, but '
- 'ManyToManyFields are not supported in "%s".') % (
+ ("'%s' refers to a ManyToManyField '%s', but "
+ "ManyToManyFields are not permitted in '%s'.") % (
option, field_name, option
),
hint=None,
obj=cls,
- id='E011',
+ id='models.E013',
)
)
return errors
@@ -1363,11 +1359,11 @@ def _check_ordering(cls):
if not isinstance(cls._meta.ordering, (list, tuple)):
return [
checks.Error(
- ('"ordering" must be a tuple or list '
- '(even if you want to order by only one field).'),
+ ("'ordering' must be a tuple or list "
+ "(even if you want to order by only one field)."),
hint=None,
obj=cls,
- id='E012',
+ id='models.E014',
)
]
@@ -1398,10 +1394,10 @@ def _check_ordering(cls):
except FieldDoesNotExist:
errors.append(
checks.Error(
- '"ordering" pointing to a missing "%s" field.' % field_name,
- hint='Ensure that you did not misspell the field name.',
+ "'ordering' refers to the non-existent field '%s'." % field_name,
+ hint=None,
obj=cls,
- id='E013',
+ id='models.E015',
)
)
return errors
12 tests/contenttypes_tests/tests.py
View
@@ -109,7 +109,7 @@ class TaggedItem(models.Model):
"The GenericForeignKey content type references the non-existent field 'TaggedItem.content_type'.",
hint=None,
obj=TaggedItem.content_object,
- id='contenttypes.E003',
+ id='contenttypes.E002',
)
]
self.assertEqual(errors, expected)
@@ -127,7 +127,7 @@ class Model(models.Model):
"'Model.content_type' is not a ForeignKey.",
hint="GenericForeignKeys must use a ForeignKey to 'contenttypes.ContentType' as the 'content_type' field.",
obj=Model.content_object,
- id='contenttypes.E004',
+ id='contenttypes.E003',
)
]
self.assertEqual(errors, expected)
@@ -145,7 +145,7 @@ class Model(models.Model):
"'Model.content_type' is not a ForeignKey to 'contenttypes.ContentType'.",
hint="GenericForeignKeys must use a ForeignKey to 'contenttypes.ContentType' as the 'content_type' field.",
obj=Model.content_object,
- id='contenttypes.E005',
+ id='contenttypes.E004',
)
]
self.assertEqual(errors, expected)
@@ -162,7 +162,7 @@ class TaggedItem(models.Model):
"The GenericForeignKey object ID references the non-existent field 'object_id'.",
hint=None,
obj=TaggedItem.content_object,
- id='contenttypes.E002',
+ id='contenttypes.E001',
)
]
self.assertEqual(errors, expected)
@@ -180,7 +180,7 @@ class Model(models.Model):
'Field names must not end with an underscore.',
hint=None,
obj=Model.content_object_,
- id='contenttypes.E001',
+ id='fields.E001',
)
]
self.assertEqual(errors, expected)
@@ -265,7 +265,7 @@ class Bookmark(models.Model):
errors = Bookmark.tags.field.check()
expected = [
- checks.Warning(
+ checks.Error(
("The GenericRelation defines a relation with the model "
"'contenttypes_tests.TaggedItem', but that model does not have a "
"GenericForeignKey."),
120 tests/invalid_models_tests/test_models.py
View
@@ -18,10 +18,10 @@ class Meta:
errors = Model.check()
expected = [
Error(
- '"index_together" must be a list or tuple.',
+ "'index_together' must be a list or tuple.",
hint=None,
obj=Model,
- id='E006',
+ id='models.E008',
),
]
self.assertEqual(errors, expected)
@@ -34,10 +34,10 @@ class Meta:
errors = Model.check()
expected = [
Error(
- '"index_together" must be a list or tuple.',
+ "'index_together' must be a list or tuple.",
hint=None,
obj=Model,
- id='E006',
+ id='models.E008',
),
]
self.assertEqual(errors, expected)
@@ -50,10 +50,10 @@ class Meta:
errors = Model.check()
expected = [
Error(
- 'All "index_together" elements must be lists or tuples.',
+ "All 'index_together' elements must be lists or tuples.",
hint=None,
obj=Model,
- id='E007',
+ id='models.E009',
),
]
self.assertEqual(errors, expected)
@@ -68,10 +68,10 @@ class Meta:
errors = Model.check()
expected = [
Error(
- '"index_together" points to a missing field named "missing_field".',
- hint='Ensure that you did not misspell the field name.',
+ "'index_together' refers to the non-existent field 'missing_field'.",
+ hint=None,
obj=Model,
- id='E010',
+ id='models.E012',
),
]
self.assertEqual(errors, expected)
@@ -88,11 +88,11 @@ class Meta:
errors = Model.check()
expected = [
Error(
- ('"index_together" refers to a m2m "m2m" field, but '
- 'ManyToManyFields are not supported in "index_together".'),
+ ("'index_together' refers to a ManyToManyField 'm2m', but "
+ "ManyToManyFields are not permitted in 'index_together'."),
hint=None,
obj=Model,
- id='E011',
+ id='models.E013',
),
]
self.assertEqual(errors, expected)
@@ -109,10 +109,10 @@ class Meta:
errors = Model.check()
expected = [
Error(
- '"unique_together" must be a list or tuple.',
+ "'unique_together' must be a list or tuple.",
hint=None,
obj=Model,
- id='E008',
+ id='models.E010',
),
]
self.assertEqual(errors, expected)
@@ -128,10 +128,10 @@ class Meta:
errors = Model.check()
expected = [
Error(
- 'All "unique_together" elements must be lists or tuples.',
+ "All 'unique_together' elements must be lists or tuples.",
hint=None,
obj=Model,
- id='E009',
+ id='models.E011',
),
]
self.assertEqual(errors, expected)
@@ -144,10 +144,10 @@ class Meta:
errors = Model.check()
expected = [
Error(
- '"unique_together" must be a list or tuple.',
+ "'unique_together' must be a list or tuple.",
hint=None,
obj=Model,
- id='E008',
+ id='models.E010',
),
]
self.assertEqual(errors, expected)
@@ -174,10 +174,10 @@ class Meta:
errors = Model.check()
expected = [
Error(
- '"unique_together" points to a missing field named "missing_field".',
- hint='Ensure that you did not misspell the field name.',
+ "'unique_together' refers to the non-existent field 'missing_field'.",
+ hint=None,
obj=Model,
- id='E010',
+ id='models.E012',
),
]
self.assertEqual(errors, expected)
@@ -194,11 +194,11 @@ class Meta:
errors = Model.check()
expected = [
Error(
- ('"unique_together" refers to a m2m "m2m" field, but '
- 'ManyToManyFields are not supported in "unique_together".'),
+ ("'unique_together' refers to a ManyToManyField 'm2m', but "
+ "ManyToManyFields are not permitted in 'unique_together'."),
hint=None,
obj=Model,
- id='E011',
+ id='models.E013',
),
]
self.assertEqual(errors, expected)
@@ -276,20 +276,20 @@ class Child(Mother, Father):
errors = Child.check()
expected = [
Error(
- ('The field "id" from parent model '
- 'invalid_models_tests.mother clashes with the field "id" '
- 'from parent model invalid_models_tests.father.'),
+ ("The field 'id' from parent model "
+ "'invalid_models_tests.mother' clashes with the field 'id' "
+ "from parent model 'invalid_models_tests.father'."),
hint=None,
obj=Child,
- id='E053',
+ id='models.E005',
),
Error(
- ('The field "clash" from parent model '
- 'invalid_models_tests.mother clashes with the field "clash" '
- 'from parent model invalid_models_tests.father.'),
+ ("The field 'clash' from parent model "
+ "'invalid_models_tests.mother' clashes with the field 'clash' "
+ "from parent model 'invalid_models_tests.father'."),
hint=None,
obj=Child,
- id='E053',
+ id='models.E005',
)
]
self.assertEqual(errors, expected)
@@ -309,11 +309,11 @@ class Child(Parent):
errors = Child.check()
expected = [
Error(
- ('The field clashes with the field "f_id" '
- 'from model invalid_models_tests.parent.'),
+ ("The field 'f' clashes with the field 'f_id' "
+ "from model 'invalid_models_tests.parent'."),
hint=None,
obj=Child._meta.get_field('f'),
- id='E054',
+ id='models.E006',
)
]
self.assertEqual(errors, expected)
@@ -329,11 +329,11 @@ class Model(models.Model):
errors = Model.check()
expected = [
Error(
- ('The field clashes with the field "fk" from model '
- 'invalid_models_tests.model.'),
+ ("The field 'fk_id' clashes with the field 'fk' from model "
+ "'invalid_models_tests.model'."),
hint=None,
obj=Model._meta.get_field('fk_id'),
- id='E054',
+ id='models.E006',
)
]
self.assertEqual(errors, expected)
@@ -350,12 +350,10 @@ class Model(models.Model):
errors = Model.check()
expected = [
Error(
- ('You cannot use "id" as a field name, because each model '
- 'automatically gets an "id" field if none of the fields '
- 'have primary_key=True.'),
- hint='Remove or rename "id" field or add primary_key=True to a field.',
+ "'id' can only be used as a field name if the field also sets 'primary_key=True'.",
+ hint=None,
obj=Model,
- id='E005',
+ id='models.E004',
),
]
self.assertEqual(errors, expected)
@@ -368,11 +366,11 @@ class Meta:
errors = Model.check()
expected = [
Error(
- ('"ordering" must be a tuple or list '
- '(even if you want to order by only one field).'),
+ ("'ordering' must be a tuple or list "
+ "(even if you want to order by only one field)."),
hint=None,
obj=Model,
- id='E012',
+ id='models.E014',
),
]
self.assertEqual(errors, expected)
@@ -385,10 +383,10 @@ class Meta:
errors = Model.check()
expected = [
Error(
- '"ordering" pointing to a missing "missing_field" field.',
- hint='Ensure that you did not misspell the field name.',
+ "'ordering' refers to the non-existent field 'missing_field'.",
+ hint=None,
obj=Model,
- id='E013',
+ id='models.E015',
)
]
self.assertEqual(errors, expected)
@@ -402,10 +400,10 @@ class Meta:
errors = Model.check()
expected = [
Error(
- '"TEST_SWAPPED_MODEL_BAD_VALUE" is not of the form "app_label.app_name".',
+ "'TEST_SWAPPED_MODEL_BAD_VALUE' is not of the form 'app_label.app_name'.",
hint=None,
- obj=Model,
- id='E002',
+ obj=None,
+ id='models.E001',
),
]
self.assertEqual(errors, expected)
@@ -419,13 +417,11 @@ class Meta:
errors = Model.check()
expected = [
Error(
- ('The model has been swapped out for not_an_app.Target '
- 'which has not been installed or is abstract.'),
- hint=('Ensure that you did not misspell the model name and '
- 'the app name as well as the model is not abstract. Does '
- 'your INSTALLED_APPS setting contain the "not_an_app" app?'),
- obj=Model,
- id='E003',
+ ("'TEST_SWAPPED_MODEL_BAD_MODEL' references 'not_an_app.Target', "
+ 'which has not been installed, or is abstract.'),
+ hint=None,
+ obj=None,
+ id='models.E002',
),
]
self.assertEqual(errors, expected)
@@ -447,11 +443,11 @@ class Membership(models.Model):
errors = Group.check()
expected = [
Error(
- ('The model has two many-to-many relations through '
- 'the intermediary Membership model, which is not permitted.'),
+ ("The model has two many-to-many relations through "
+ "the intermediate model 'invalid_models_tests.Membership'."),
hint=None,
obj=Group,
- id='E004',
+ id='models.E003',
)
]
self.assertEqual(errors, expected)
Please sign in to comment.
Something went wrong with that request. Please try again.