django admin重写列表页面返回的查询集

class MagazineCommentInfoAdmin(object):
    list_display = ('magazine_link', 'nickname', 'comment', 'device', 'time')
    ordering = ('magazine',)
    list_display_links = ('magazine_link', 'comment',)
    search_fields = ['magazine__name', ]
    list_filter = ('deleted',)


    def magazine_link(self, obj):
        return '<a href="?magazine=%s">%s</a>' % (obj.magazine.id, obj.magazine)


    magazine_link.allow_tags = True
    magazine_link.short_description = "magazine"




    def queryset(self):
        magazine_id = self.request.GET.get("magazine", None)
        qs = super(MagazineCommentInfoAdmin, self).queryset()
        if not magazine_id:
            return qs
        else:
            qs = qs.filter(magazine__id=magazine_id)
            return qs

你可能感兴趣的:(django,admin)