From e187caa3afd7d292353fb32be1647da2cf0968da Mon Sep 17 00:00:00 2001 From: Aymeric Augustin Date: Mon, 30 Dec 2013 12:49:53 +0100 Subject: [PATCH] Added AppConfig.setup() to run setup code. --- django/apps/base.py | 5 +++++ django/apps/registry.py | 3 +++ docs/ref/applications.txt | 6 ++++++ 3 files changed, 14 insertions(+) diff --git a/django/apps/base.py b/django/apps/base.py index 784c460bcd..eaf8993624 100644 --- a/django/apps/base.py +++ b/django/apps/base.py @@ -162,3 +162,8 @@ class AppConfig(object): if module_has_submodule(self.module, MODELS_MODULE_NAME): models_module_name = '%s.%s' % (self.name, MODELS_MODULE_NAME) self.models_module = import_module(models_module_name) + + def setup(self): + """ + Override this method in subclasses to run setup code. + """ diff --git a/django/apps/registry.py b/django/apps/registry.py index 1bb00f37f7..c23fe69362 100644 --- a/django/apps/registry.py +++ b/django/apps/registry.py @@ -135,6 +135,9 @@ class Apps(object): self.clear_cache() self._models_loaded = True + for app_config in self.get_app_configs(): + app_config.setup() + @property def ready(self): """ diff --git a/docs/ref/applications.txt b/docs/ref/applications.txt index 8505784737..5d9db49140 100644 --- a/docs/ref/applications.txt +++ b/docs/ref/applications.txt @@ -166,6 +166,12 @@ Methods ``model_name``. Raises :exc:`~exceptions.LookupError` if no such model 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 ====================