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