django admin super(type, obj) -
well, let me explain this.
i working on simple django admin project.
in admin.py file, have following admin classes:
class a_admin(admin.modeladmin): #some stuff class b_admin(admin.modeladmin): #some stuff
i want override get_urls() method of a_admin if click button on a_admin instance change page, redirect page b_admin changelist page.
(i know there many ways want , mentioned above not best, want. let skip discussion why insist on solution.)
i want following:
def get_urls(self): #django's code #inside urlpattern urlpattern = ( #default urls django admin ..... url(r'^some_url$', wrap(super(b_admin, self).changelist_view), name='%s_%s_delete' % info), ....) return urlpatterns
this not working, since 'self' a_admin class object rather b_admin obejct.
so there way proxy of calss a_admin inside b_admin? wanna override changelist_view of , call inside b.
is possible?
thanks in advance
you should instantiate b_admin , use method.
i believe following code should work:
from django.contrib import admin my_app.models import b_model # model b_admin used def get_urls(self): #django's code #inside urlpattern urlpattern = ( #default urls django admin ..... url(r'^some_url$', wrap(b_admin(b_model, admin.site).changelist_view), name='%s_%s_delete' % info), ....) return urlpatterns
update: probably, b_admin
instantiated when called
admin.site.register(b_model, b_admin)
so instead of doing
b_admin(b_model, admin.site)
again can adminsite
's registry:
admin.site._registry[b_model]
Comments
Post a Comment