您需要创建一个自定义列表过滤器,django.contrib.admin.filters.SimpleListFilter
默认情况下从未关闭的帐户继承和过滤。这些方面的东西应该起作用:
from datetime import date
from django.utils.translation import ugettext_lazy as _
from django.contrib.admin import SimpleListFilter
class IsClosedFilter(SimpleListFilter):
title = _('Closed')
parameter_name = 'closed'
def lookups(self, request, model_admin):
return (
(None, _('No')),
('yes', _('Yes')),
('all', _('All')),
)
def choices(self, cl):
for lookup, title in self.lookup_choices:
yield {
'selected': self.value() == lookup,
'query_string': cl.get_query_string({
self.parameter_name: lookup,
}, []),
'display': title,
}
def queryset(self, request, queryset):
if self.value() == 'closed':
return queryset.filter(isClosed=True)
elif self.value() is None:
return queryset.filter(isClosed=False)
class Admin(admin.ModelAdmin):
list_filter = [isClosedFilter]