我想为django admin而不是普通的'is_staff'和'is_superuser'制作自定义过滤器.我在Django docs中读过这个list_filter.自定义过滤器以这种方式工作:
from datetime import date
from django.utils.translation import ugettext_lazy as _
from django.contrib.admin import SimpleListFilter
class DecadeBornListFilter(SimpleListFilter):
# Human-readable title which will be displayed in the
# right admin sidebar just above the filter options.
title = _('decade born')
# Parameter for the filter that will be used in the URL query.
parameter_name = 'decade'
def lookups(self, request, model_admin):
"""
Returns a list of tuples. The first element in each
tuple is the coded value for …Run Code Online (Sandbox Code Playgroud)