我认为您需要覆盖changelist_view
并对其TemplateResponse()
返回的值采取行动,或者在调用之前更改持有该名称的变量。
原来的功能是这样的
def changelist_view(self, request, extra_context=None):
# a lot of stuff happen here
return TemplateResponse(request, self.change_list_template or [
'admin/%s/%s/change_list.html' % (app_label, opts.object_name.lower()),
'admin/%s/change_list.html' % app_label,
'admin/change_list.html'
], context, current_app=self.admin_site.name)
所以我认为这样的代码
def changelist(self, request, extra_context=None):
if request.GET['foo']:
self.change_list_template = "students/student_change_list_other.html"
return super(STUDENTAdmin, self).changelist_view(request, extra_context)