summaryrefslogtreecommitdiff
path: root/django/apps/config.py
diff options
context:
space:
mode:
authorAymeric Augustin <aymeric.augustin@m4x.org>2014-07-12 15:33:21 +0200
committerAymeric Augustin <aymeric.augustin@m4x.org>2014-07-12 18:49:37 +0200
commita764a9ccff6e2a2cf048e658dd824bf302c74df7 (patch)
tree3cc46c4f9f9dac7f5202c3e1839132a0c7a9699d /django/apps/config.py
parentb48c2c59253b2f2bedea40ed890f0be6ccad9f46 (diff)
Checked more precisely whether the app registry is ready.
Accounted for the three stages of population: app configs, models, ready() methods of app configs.
Diffstat (limited to 'django/apps/config.py')
-rw-r--r--django/apps/config.py15
1 files changed, 11 insertions, 4 deletions
diff --git a/django/apps/config.py b/django/apps/config.py
index dd1018b50a..9cfe4858aa 100644
--- a/django/apps/config.py
+++ b/django/apps/config.py
@@ -1,7 +1,7 @@
from importlib import import_module
import os
-from django.core.exceptions import ImproperlyConfigured
+from django.core.exceptions import AppRegistryNotReady, ImproperlyConfigured
from django.utils.module_loading import module_has_submodule
from django.utils._os import upath
@@ -139,15 +139,21 @@ 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.
"""
- if self.models is None:
- raise LookupError(
- "App '%s' doesn't have any models." % self.label)
+ self.check_models_ready()
try:
return self.models[model_name.lower()]
except KeyError:
@@ -169,6 +175,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()
for model in self.models.values():
if model._deferred and not include_deferred:
continue