def get_admin_site(current_app):
"""
Method tries to get actual admin.site class, if any custom admin sites
were used. Couldn't find any other references to actual class other than
in func_closer dict in index() func returned by resolver.
"""
try:
resolver_match = resolve(reverse('%s:index' % current_app))
# Django 1.9 exposes AdminSite instance directly on view function
if hasattr(resolver_match.func, 'admin_site'):
return resolver_match.func.admin_site
for func_closure in resolver_match.func.__closure__:
if isinstance(func_closure.cell_contents, AdminSite):
return func_closure.cell_contents
except:
pass
from django.contrib import admin
return admin.site
评论列表
文章目录