diff options
| author | Juan Catalano <catalanojuan@gmail.com> | 2013-09-06 20:23:25 -0300 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2013-09-13 20:09:41 -0400 |
| commit | 6feb75129f42fdac751d0b79a2a005b4c0ad5c2d (patch) | |
| tree | 5bb6cbb83482c15af59cfce69ae2339ff2aa0f3d /django/contrib/admin/__init__.py | |
| parent | 39b49fd33970720b973498d2c8275ced129d3a7a (diff) | |
Fixed #21060 -- Refactored admin's autodiscover method to make it reusable.
We want to be able to use it for instance for discovering `tasks.py` modules
inside the INSTALLED_APPS.
This commit therefore moves the logic to `autodiscover_modules` method in
django.utils.module_loading.
Diffstat (limited to 'django/contrib/admin/__init__.py')
| -rw-r--r-- | django/contrib/admin/__init__.py | 31 |
1 files changed, 2 insertions, 29 deletions
diff --git a/django/contrib/admin/__init__.py b/django/contrib/admin/__init__.py index ef2e87407a..3975993679 100644 --- a/django/contrib/admin/__init__.py +++ b/django/contrib/admin/__init__.py @@ -7,35 +7,8 @@ from django.contrib.admin.sites import AdminSite, site from django.contrib.admin.filters import (ListFilter, SimpleListFilter, FieldListFilter, BooleanFieldListFilter, RelatedFieldListFilter, ChoicesFieldListFilter, DateFieldListFilter, AllValuesFieldListFilter) +from django.utils.module_loading import autodiscover_modules def autodiscover(): - """ - Auto-discover INSTALLED_APPS admin.py modules and fail silently when - not present. This forces an import on them to register any admin bits they - may want. - """ - - import copy - from importlib import import_module - from django.conf import settings - from django.utils.module_loading import module_has_submodule - - for app in settings.INSTALLED_APPS: - mod = import_module(app) - # Attempt to import the app's admin module. - try: - before_import_registry = copy.copy(site._registry) - import_module('%s.admin' % app) - except: - # Reset the model registry to the state before the last import as - # this import will have to reoccur on the next request and this - # could raise NotRegistered and AlreadyRegistered exceptions - # (see #8245). - site._registry = before_import_registry - - # Decide whether to bubble up this error. If the app just - # doesn't have an admin module, we can ignore the error - # attempting to import it, otherwise we want it to bubble up. - if module_has_submodule(mod, 'admin'): - raise + autodiscover_modules('admin', register_to=site) |
