equal
deleted
inserted
replaced
|
1 from django.contrib.admin.helpers import ACTION_CHECKBOX_NAME |
|
2 from django.contrib.admin.options import ModelAdmin, HORIZONTAL, VERTICAL |
|
3 from django.contrib.admin.options import StackedInline, TabularInline |
|
4 from django.contrib.admin.sites import AdminSite, site |
|
5 |
|
6 |
|
7 def autodiscover(): |
|
8 """ |
|
9 Auto-discover INSTALLED_APPS admin.py modules and fail silently when |
|
10 not present. This forces an import on them to register any admin bits they |
|
11 may want. |
|
12 """ |
|
13 |
|
14 import copy |
|
15 from django.conf import settings |
|
16 from django.utils.importlib import import_module |
|
17 from django.utils.module_loading import module_has_submodule |
|
18 |
|
19 for app in settings.INSTALLED_APPS: |
|
20 mod = import_module(app) |
|
21 # Attempt to import the app's admin module. |
|
22 try: |
|
23 before_import_registry = copy.copy(site._registry) |
|
24 import_module('%s.admin' % app) |
|
25 except: |
|
26 # Reset the model registry to the state before the last import as |
|
27 # this import will have to reoccur on the next request and this |
|
28 # could raise NotRegistered and AlreadyRegistered exceptions |
|
29 # (see #8245). |
|
30 site._registry = before_import_registry |
|
31 |
|
32 # Decide whether to bubble up this error. If the app just |
|
33 # doesn't have an admin module, we can ignore the error |
|
34 # attempting to import it, otherwise we want it to bubble up. |
|
35 if module_has_submodule(mod, 'admin'): |
|
36 raise |