summaryrefslogtreecommitdiff
path: root/django/apps
diff options
context:
space:
mode:
authorAymeric Augustin <aymeric.augustin@m4x.org>2016-09-30 21:08:35 +0200
committerTim Graham <timograham@gmail.com>2016-10-28 18:42:29 -0400
commitefcb7e1ebf2b852a442d00a31634438359eb4039 (patch)
treecce88cc9cb2093fca4fe9a764bcce803d2be7d81 /django/apps
parent20be1918e77414837178d6bf1657068c8306d50c (diff)
Modified readiness check in AppConfig.get_model(s).
It was inconsistent with the equivalent check in Apps.get_model(s) because I made incorrect assumptions when I wrote that code and needlessly complicated readiness checks. This is a backwards-incompatible change.
Diffstat (limited to 'django/apps')
-rw-r--r--django/apps/config.py18
-rw-r--r--django/apps/registry.py1
2 files changed, 8 insertions, 11 deletions
diff --git a/django/apps/config.py b/django/apps/config.py
index 88e52c1f05..178fe97130 100644
--- a/django/apps/config.py
+++ b/django/apps/config.py
@@ -1,7 +1,7 @@
import os
from importlib import import_module
-from django.core.exceptions import AppRegistryNotReady, ImproperlyConfigured
+from django.core.exceptions import ImproperlyConfigured
from django.utils._os import upath
from django.utils.module_loading import module_has_submodule
@@ -21,6 +21,10 @@ class AppConfig(object):
# from 'django/contrib/admin/__init__.pyc'>.
self.module = app_module
+ # Reference to the Apps registry that holds this AppConfig. Set by the
+ # registry when it registers the AppConfig instance.
+ self.apps = None
+
# The following attributes could be defined at the class level in a
# subclass, hence the test-and-set pattern.
@@ -151,21 +155,13 @@ class AppConfig(object):
# Entry is a path to an app config class.
return cls(app_name, app_module)
- def check_models_ready(self):
- """
- Raises an exception if models haven't been imported yet.
- """
- if self.models is None:
- raise AppRegistryNotReady(
- "Models for app '%s' haven't been imported yet." % self.label)
-
def get_model(self, model_name):
"""
Returns the model with the given case-insensitive model_name.
Raises LookupError if no model exists with this name.
"""
- self.check_models_ready()
+ self.apps.check_models_ready()
try:
return self.models[model_name.lower()]
except KeyError:
@@ -186,7 +182,7 @@ class AppConfig(object):
Set the corresponding keyword argument to True to include such models.
Keyword arguments aren't documented; they're a private API.
"""
- self.check_models_ready()
+ self.apps.check_models_ready()
for model in self.models.values():
if model._meta.auto_created and not include_auto_created:
continue
diff --git a/django/apps/registry.py b/django/apps/registry.py
index 8a45830ccf..91d6d5ccef 100644
--- a/django/apps/registry.py
+++ b/django/apps/registry.py
@@ -89,6 +89,7 @@ class Apps(object):
"duplicates: %s" % app_config.label)
self.app_configs[app_config.label] = app_config
+ app_config.apps = self
# Check for duplicate app names.
counts = Counter(