diff --git a/django/contrib/admin/__init__.py b/django/contrib/admin/__init__.py
index 56b64fa..0ca5fa0 100644
a
|
b
|
|
| 1 | from django.utils.importutils import getattr_import, module_or_none |
1 | 2 | from django.contrib.admin.options import ModelAdmin, HORIZONTAL, VERTICAL |
2 | 3 | from django.contrib.admin.options import StackedInline, TabularInline |
3 | 4 | from django.contrib.admin.sites import AdminSite, site |
… |
… |
def autodiscover():
|
10 | 11 | """ |
11 | 12 | from django.conf import settings |
12 | 13 | for app in settings.INSTALLED_APPS: |
13 | | try: |
14 | | __import__("%s.admin" % app) |
15 | | except ImportError: |
16 | | pass |
| 14 | mod = module_or_none(app) |
| 15 | if mod: |
| 16 | try: |
| 17 | imp.find_module('admin', mod.__path__) |
| 18 | except ImportError: |
| 19 | # There is no admin.py, skip it |
| 20 | continue |
| 21 | else: |
| 22 | continue |
| 23 | getattr_import('%s.admin' % app) |
diff --git a/django/utils/importutils.py b/django/utils/importutils.py
new file mode 100644
index 0000000..8b58d7a
-
|
+
|
|
| 1 | def getattr_import(module_name): |
| 2 | components = module_name.split('.') |
| 3 | mod = __import__(module_name) |
| 4 | for comp in components[1:]: |
| 5 | mod = getattr(mod, comp) |
| 6 | |
| 7 | def module_or_none(module_name): |
| 8 | try: |
| 9 | return getattr_import(module_name) |
| 10 | except (ImportError, AttributeError): |
| 11 | return None |
| 12 | |
| 13 | |