1
0
mirror of https://github.com/django/django.git synced 2025-10-24 06:06:09 +00:00

Deprecated importing a model before loading its application.

Refs #21719, #21680.
This commit is contained in:
Aymeric Augustin
2014-01-10 23:06:19 +01:00
parent 81bb8d1220
commit 3326a412cc
5 changed files with 40 additions and 5 deletions

View File

@@ -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'