summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authormichaldabski <contact@michaldabski.com>2017-06-15 21:44:20 +0100
committerTim Graham <timograham@gmail.com>2017-06-26 18:12:35 -0400
commitd381914aef50e04ca44b9d7bb9274c8351f5b9bf (patch)
tree22cb66be3571f5f4f20fa02efbdb93720b6c778c /django
parent44a7b98abbec02f1a4f35662040f602fd616d0cd (diff)
Fixed #28313 -- Added model name max length check of 100 characters in contrib.contentttypes.
Diffstat (limited to 'django')
-rw-r--r--django/contrib/contenttypes/apps.py5
-rw-r--r--django/contrib/contenttypes/checks.py21
2 files changed, 25 insertions, 1 deletions
diff --git a/django/contrib/contenttypes/apps.py b/django/contrib/contenttypes/apps.py
index 095dbf5615..1a8e25b98e 100644
--- a/django/contrib/contenttypes/apps.py
+++ b/django/contrib/contenttypes/apps.py
@@ -1,5 +1,7 @@
from django.apps import AppConfig
-from django.contrib.contenttypes.checks import check_generic_foreign_keys
+from django.contrib.contenttypes.checks import (
+ check_generic_foreign_keys, check_model_name_lengths,
+)
from django.core import checks
from django.db.models.signals import post_migrate, pre_migrate
from django.utils.translation import gettext_lazy as _
@@ -17,3 +19,4 @@ class ContentTypesConfig(AppConfig):
pre_migrate.connect(inject_rename_contenttypes_operations, sender=self)
post_migrate.connect(create_contenttypes)
checks.register(check_generic_foreign_keys, checks.Tags.models)
+ checks.register(check_model_name_lengths, checks.Tags.models)
diff --git a/django/contrib/contenttypes/checks.py b/django/contrib/contenttypes/checks.py
index d21df40f46..3e802ea26b 100644
--- a/django/contrib/contenttypes/checks.py
+++ b/django/contrib/contenttypes/checks.py
@@ -1,6 +1,7 @@
from itertools import chain
from django.apps import apps
+from django.core.checks import Error
def check_generic_foreign_keys(app_configs=None, **kwargs):
@@ -18,3 +19,23 @@ def check_generic_foreign_keys(app_configs=None, **kwargs):
for field in fields:
errors.extend(field.check())
return errors
+
+
+def check_model_name_lengths(app_configs=None, **kwargs):
+ if app_configs is None:
+ models = apps.get_models()
+ else:
+ models = chain.from_iterable(app_config.get_models() for app_config in app_configs)
+ errors = []
+ for model in models:
+ if len(model._meta.model_name) > 100:
+ errors.append(
+ Error(
+ 'Model names must be at most 100 characters (got %d).' % (
+ len(model._meta.model_name),
+ ),
+ obj=model,
+ id='contenttypes.E005',
+ )
+ )
+ return errors