summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--django/apps/config.py6
-rw-r--r--django/apps/registry.py8
-rw-r--r--django/db/migrations/state.py4
3 files changed, 8 insertions, 10 deletions
diff --git a/django/apps/config.py b/django/apps/config.py
index 178fe97130..72c5121411 100644
--- a/django/apps/config.py
+++ b/django/apps/config.py
@@ -190,12 +190,10 @@ class AppConfig(object):
continue
yield model
- def import_models(self, all_models):
+ def import_models(self):
# Dictionary of models for this app, primarily maintained in the
# 'all_models' attribute of the Apps this AppConfig is attached to.
- # Injected as a parameter because it gets populated when models are
- # imported, which might happen before populate() imports models.
- self.models = all_models
+ self.models = self.apps.all_models[self.label]
if module_has_submodule(self.module, MODELS_MODULE_NAME):
models_module_name = '%s.%s' % (self.name, MODELS_MODULE_NAME)
diff --git a/django/apps/registry.py b/django/apps/registry.py
index 91d6d5ccef..adf6cbf753 100644
--- a/django/apps/registry.py
+++ b/django/apps/registry.py
@@ -77,7 +77,7 @@ class Apps(object):
if self.app_configs:
raise RuntimeError("populate() isn't reentrant")
- # Load app configs and app modules.
+ # Phase 1: initialize app configs and import app modules.
for entry in installed_apps:
if isinstance(entry, AppConfig):
app_config = entry
@@ -103,15 +103,15 @@ class Apps(object):
self.apps_ready = True
- # Load models.
+ # Phase 2: import models modules.
for app_config in self.app_configs.values():
- all_models = self.all_models[app_config.label]
- app_config.import_models(all_models)
+ app_config.import_models()
self.clear_cache()
self.models_ready = True
+ # Phase 3: run ready() methods of app configs.
for app_config in self.get_app_configs():
app_config.ready()
diff --git a/django/db/migrations/state.py b/django/db/migrations/state.py
index 60d192443b..1a9c23e618 100644
--- a/django/db/migrations/state.py
+++ b/django/db/migrations/state.py
@@ -214,8 +214,8 @@ class AppConfigStub(AppConfig):
# the app name, but we need something unique, and the label works fine.
super(AppConfigStub, self).__init__(label, None)
- def import_models(self, all_models):
- self.models = all_models
+ def import_models(self):
+ self.models = self.apps.all_models[self.label]
class StateApps(Apps):