Added AppConfig.setup() to run setup code.

This commit is contained in:
Aymeric Augustin 2013-12-30 12:49:53 +01:00
parent 0d2c8ff2be
commit e187caa3af
3 changed files with 14 additions and 0 deletions

View File

@ -162,3 +162,8 @@ class AppConfig(object):
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)
self.models_module = import_module(models_module_name) self.models_module = import_module(models_module_name)
def setup(self):
"""
Override this method in subclasses to run setup code.
"""

View File

@ -135,6 +135,9 @@ class Apps(object):
self.clear_cache() self.clear_cache()
self._models_loaded = True self._models_loaded = True
for app_config in self.get_app_configs():
app_config.setup()
@property @property
def ready(self): def ready(self):
""" """

View File

@ -166,6 +166,12 @@ Methods
``model_name``. Raises :exc:`~exceptions.LookupError` if no such model ``model_name``. Raises :exc:`~exceptions.LookupError` if no such model
exists. ``model_name`` is case-insensitive. exists. ``model_name`` is case-insensitive.
.. method:: AppConfig.setup()
Subclasses can override this method to perform setup tasks such as
registering signals. It is called as soon as the registry is fully
populated.
Application registry Application registry
==================== ====================