On Fri, Jan 22, 2016 at 11:38 PM, Luis Masuelli <luisfmasuelli@gmail.com> wrote:
I would like to create a custom AdminSite instance, using a custom subclass of my own, and provide some project-level urls for the AdminSite. However, I would like to still benefit from the autodiscover feature.Is there a way I can instance a custom AdminSite subclass, and have that instance reachable as `admin.site` import path? This means, the following line:from django.contrib.admin import site
returning my custom AdminSite instance, if I want to override it. In this way, installed apps register their model admins against my custom AdminSite instance. For this to work, I want this to be executed before the autodiscover process is run in the app registry.How can I do it?
You can use django.contrib.admin.apps.SimpleAdminConfig and call autodiscover yourself.
In your settings
INSTALLED_APPS = [
...
"django.contrib.admin.apps.SimpleAdminConfig",
...
"myproject.apps.Config",
...
]
and in myproject/apps.py
from django.apps import AppConfig
from django.utils.translation import ugettext_lazy as _
class Config(AppConfig):
name = "myproject"
verbose_name = _("My Project")
def ready(self):
super(Config, self).ready()
from django.contrib import admin
from myproject.admin.sites import site
admin.site = site
admin.autodiscover()
| Raffaele Salmaso
| https://salmaso.org
| https://bitbucket.org/rsalmaso
| https://github.com/rsalmaso
| https://salmaso.org
| https://bitbucket.org/rsalmaso
| https://github.com/rsalmaso
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CABgH4JukPvnT-U%2BkS7YkGVi-4A8d97fOdY3xZULc320tG9u5ow%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment