一、举例
class CategoryTreeRelatedFieldListFilter(admin.SimpleListFilter):
title = _('课程章节')
parameter_name = 'chapter' def lookups(self, request, model_admin):
chapter = Category.objects.filter(level=2)
res = []
for c in chapter:
res.append((c.id,c.name))
return res #它返回过去的值给了request.GEt def queryset(self, request, queryset):
chapter = request.GET
if not chapter:
return queryset return Category.objects.get(id=chapter['chapter']).coursewares.all()
class CourseWareAdmin(admin.ModelAdmin):
change_form_template = 'infrastructure/courseware_change_form.html'
change_list_template = 'infrastructure/courseware_change_list.html'
search_fields = ('name',) list_filter = ['tags5__name', CategoryTreeRelatedFieldListFilter]