Simplified AppConfig.import_models().
Since AppConfig now has a reference to its parent Apps registry, it can look up the models there instead of receiving them in argument.
This commit is contained in:
parent
efcb7e1ebf
commit
fd748c42a9
|
@ -190,12 +190,10 @@ class AppConfig(object):
|
||||||
continue
|
continue
|
||||||
yield model
|
yield model
|
||||||
|
|
||||||
def import_models(self, all_models):
|
def import_models(self):
|
||||||
# Dictionary of models for this app, primarily maintained in the
|
# Dictionary of models for this app, primarily maintained in the
|
||||||
# 'all_models' attribute of the Apps this AppConfig is attached to.
|
# 'all_models' attribute of the Apps this AppConfig is attached to.
|
||||||
# Injected as a parameter because it gets populated when models are
|
self.models = self.apps.all_models[self.label]
|
||||||
# imported, which might happen before populate() imports models.
|
|
||||||
self.models = all_models
|
|
||||||
|
|
||||||
if module_has_submodule(self.module, MODELS_MODULE_NAME):
|
if module_has_submodule(self.module, MODELS_MODULE_NAME):
|
||||||
models_module_name = '%s.%s' % (self.name, MODELS_MODULE_NAME)
|
models_module_name = '%s.%s' % (self.name, MODELS_MODULE_NAME)
|
||||||
|
|
|
@ -77,7 +77,7 @@ class Apps(object):
|
||||||
if self.app_configs:
|
if self.app_configs:
|
||||||
raise RuntimeError("populate() isn't reentrant")
|
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:
|
for entry in installed_apps:
|
||||||
if isinstance(entry, AppConfig):
|
if isinstance(entry, AppConfig):
|
||||||
app_config = entry
|
app_config = entry
|
||||||
|
@ -103,15 +103,15 @@ class Apps(object):
|
||||||
|
|
||||||
self.apps_ready = True
|
self.apps_ready = True
|
||||||
|
|
||||||
# Load models.
|
# Phase 2: import models modules.
|
||||||
for app_config in self.app_configs.values():
|
for app_config in self.app_configs.values():
|
||||||
all_models = self.all_models[app_config.label]
|
app_config.import_models()
|
||||||
app_config.import_models(all_models)
|
|
||||||
|
|
||||||
self.clear_cache()
|
self.clear_cache()
|
||||||
|
|
||||||
self.models_ready = True
|
self.models_ready = True
|
||||||
|
|
||||||
|
# Phase 3: run ready() methods of app configs.
|
||||||
for app_config in self.get_app_configs():
|
for app_config in self.get_app_configs():
|
||||||
app_config.ready()
|
app_config.ready()
|
||||||
|
|
||||||
|
|
|
@ -214,8 +214,8 @@ class AppConfigStub(AppConfig):
|
||||||
# the app name, but we need something unique, and the label works fine.
|
# the app name, but we need something unique, and the label works fine.
|
||||||
super(AppConfigStub, self).__init__(label, None)
|
super(AppConfigStub, self).__init__(label, None)
|
||||||
|
|
||||||
def import_models(self, all_models):
|
def import_models(self):
|
||||||
self.models = all_models
|
self.models = self.apps.all_models[self.label]
|
||||||
|
|
||||||
|
|
||||||
class StateApps(Apps):
|
class StateApps(Apps):
|
||||||
|
|
Loading…
Reference in New Issue