summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorAymeric Augustin <aymeric.augustin@m4x.org>2014-01-10 23:06:19 +0100
committerAymeric Augustin <aymeric.augustin@m4x.org>2014-01-10 23:43:10 +0100
commit3326a412ccde9f72e22a070a0b4d922048ed2286 (patch)
tree7583ee99e53ab3d3bf846f1aec79dc34d330d2cf /django
parent81bb8d12209a419142b1bf6961fbf9fc44419dcd (diff)
Deprecated importing a model before loading its application.
Refs #21719, #21680.
Diffstat (limited to 'django')
-rw-r--r--django/db/models/base.py10
1 files changed, 9 insertions, 1 deletions
diff --git a/django/db/models/base.py b/django/db/models/base.py
index 531dd8adcc..d7b54b9268 100644
--- a/django/db/models/base.py
+++ b/django/db/models/base.py
@@ -3,7 +3,7 @@ from __future__ import unicode_literals
import copy
import sys
from functools import update_wrapper
-from django.utils.six.moves import zip
+import warnings
from django.apps import apps
from django.apps.base import MODELS_MODULE_NAME
@@ -25,6 +25,7 @@ from django.utils.translation import ugettext_lazy as _
from django.utils.functional import curry
from django.utils.encoding import force_str, force_text
from django.utils import six
+from django.utils.six.moves import zip
from django.utils.text import get_text_list, capfirst
@@ -103,6 +104,13 @@ class ModelBase(type):
# For 'django.contrib.sites.models', this would be 'sites'.
# For 'geo.models.places' this would be 'geo'.
+ warnings.warn(
+ "Model class %s.%s doesn't declare an explicit app_label "
+ "and either isn't in an application in INSTALLED_APPS "
+ "or else was imported before its application was loaded. "
+ "This will no longer be supported in Django 1.9."
+ % (module, name), PendingDeprecationWarning, stacklevel=2)
+
model_module = sys.modules[new_class.__module__]
package_components = model_module.__name__.split('.')
package_components.reverse() # find the last occurrence of 'models'