django管理列表页面视图

时间:2012-07-25 06:21:13

标签: django django-admin

如何使用视图自定义django管理列表页面以及如何在模板change_list.html中传递值以显示django admin list page中的新字段

我尝试在admin中编写列表视图:

def get_urls(self):
        urls = super(BeneficiaryAdmin, self).get_urls()
        my_urls = patterns('',
            (r'^list_view/$', self.list_view)
        )
        return my_urls + urls

def list_view(self, request):
        print "kkkkkkkkkkkkkkkkkkkkkkkkkk"
        # custom view which should return an HttpResponse
        return HttpResponseRedirect("/dashboard/member_management/beneficiary/")

但是list_view不可调用。

2 个答案:

答案 0 :(得分:0)

您是否阅读过Overriding admin templates

答案 1 :(得分:0)

def changelist_view(self, request, extra_context=None):
        from django.contrib.admin.views.main import ChangeList
        cl = ChangeList(request, self.model, list(self.list_display), 
                        self.list_display_links, self.list_filter, 
                        self.date_hierarchy, self.search_fields,  
                        self.list_select_related, 
                        self.list_per_page, 
                        self.list_editable, 
                        self)

        if extra_context is None: 
            extra_context = {}
return super(BeneficiaryAdmin, self).changelist_view(request, extra_context=extra_context)

我们可以使用此编辑列表视图页面。