Closed pythoniste closed 1 year ago
Hi @pythoniste you can do something like that:
autodiscover/admin.py
file with the following content (also include an __init__.py
in the autodiscover
folder):from django.http import HttpResponse
from django.contrib import admin
from baton.autodiscover.admin import BatonAdminSite
class MyAdminSite(BatonAdminSite):
def index(self, request, extra_context=None):
return HttpResponse("I'm working!")
site = MyAdminSite()
# override otherwise in admindocs the default admin site is used showing
# the navbar
admin.site = site
INSTALLED_APP
replace baton.autodiscover
with your app_name.autodiscover
(as the last listed app)urls.py
replace the baton autodiscover import:# from baton.autodiscover import admin # comment out this line
from app_name.autodiscover import admin # add this line
And everything should work
Closing this, feel free to re-open if needed.
Hello,
I need to overrides
index
method to do a redirection if some conditions are met, or let the page display otherwise.I cannot use the usual way, obviously. But i think that overriding the
BatonAdminSite
class would work. It doesn't. I tried to duplicate the code ofbaton.autodiscover
(and replace it inINSTALLED_APPS
), and override the methodindex
there, but it wont work.So, I need some help : How can I override the
index
method of the admin site ?