from django.utils.translation import ugettext_lazy as _
from django.contrib.admin import SimpleListFilter
#自定义类
class DemoFilter(SimpleListFilter):
title = _('用户ID')parameter_name = 'userId'
qs = model_admin.queryset(request).filter(book_id=request.GET['id']).values('userId').distinct()
for item in qs:
yield (item['userId'], _(item['userId']))
def queryset(self, request, queryset):
return queryset.filter(book_id=request.GET['userId'])
调用: list_filter = (DemoFilter,)
参考DJANGO文档:https://docs.djangoproject.com/en/1.4/ref/contrib/admin/