diff --git a/django/contrib/admin/__init__.py b/django/contrib/admin/__init__.py
index 56b64fa..b9ed1ff 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 not mod: |
| 16 | continue |
| 17 | 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 | |