Ticket #8500: default_admin_site_override_2.diff

File default_admin_site_override_2.diff, 1.9 KB (added by oyvind, 7 years ago)

another possible solution

  • django/contrib/admin/__init__.py

    diff --git a/django/contrib/admin/__init__.py b/django/contrib/admin/__init__.py
    index 704dc58..6f276a6 100644
    a b  
    11from django.contrib.admin.options import ModelAdmin, HORIZONTAL, VERTICAL
    22from django.contrib.admin.options import StackedInline, TabularInline
    3 from django.contrib.admin.sites import AdminSite, site
     3from django.contrib.admin.sites import AdminSite
     4
     5# This global object represents the default admin site, for the common case.
     6# You can instantiate AdminSite in your own code to create a custom admin site.
     7# It is also possible to replace the default site by passing the path to your
     8# own adminsite class to admin.set_default_site before calling admin.autodiscover().
     9
     10site = AdminSite()
     11
     12def set_default_site(import_path):
     13    try:
     14        dot = import_path.rindex('.')
     15    except ValueError:
     16        raise ImproperlyConfigured("%s isn't a adminsite class." % import_path)
     17    module, classname = import_path[:dot], import_path[dot+1:]
     18    try:
     19        mod = __import__(module, {}, {}, [''])
     20    except ImportError, e:
     21        raise ImproperlyConfigured('Error importing module %s: "%s"' % (module, e))
     22    try:
     23        site = getattr(mod, classname)()
     24    except AttributeError:
     25        raise ImproperlyConfigured('The module "%s" does not define a "%s" class.' % (module, classname))
    426
    527def autodiscover():
    628    """
  • django/contrib/admin/sites.py

    diff --git a/django/contrib/admin/sites.py b/django/contrib/admin/sites.py
    index 81e43a1..8b8062b 100644
    a b class AdminSite(object): 
    402402            'app_list': [app_dict]
    403403        }, context_instance=template.RequestContext(request))
    404404
    405 # This global object represents the default admin site, for the common case.
    406 # You can instantiate AdminSite in your own code to create a custom admin site.
    407 site = AdminSite()
Back to Top