相关疑难解决方法(0)

在Django Admin中为list_filter创建自定义过滤器

我想为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)

django django-admin

52
推荐指数
3
解决办法
4万
查看次数

标签 统计

django ×1

django-admin ×1