2013-04-03 43 views

回答

0

您是否曾尝试将其用作类属性,但我没有尝试过?

class SomeModel(models.Model): 
    @property 
    def list_filter(self): 
     """ Do your stuffs here """ 
+0

这不修复错误。 –

0

你可以写一个自定义过滤器,并通过它在list_filter

from django.contrib.admin import SimpleListFilter 

class CustomFilter(SimpleListFilter): 
    # Human-readable title which will be displayed in the 
    # right admin sidebar just above the filter options. 
    title = _('active status') 

    # Parameter for the filter that will be used in the URL query. 
    parameter_name = 'status' 

    def lookups(self, request, model_admin): 
     if request.user.is_superuser: 
      return (
       ('active', _('Active')), 
       ('not_active', _('Not Active')), 
      ) 

    def queryset(self, request, queryset): 
     # do something here with queryset 

class MyAdmin(admin.ModelAdmin): 
    list_filter = (CustomFilter, 'other_model_field') 

请参阅here,了解更多有关ModelAdmin.list_filter

+0

我提供的文档链接检查'DecadeBornListFilter'示例,它一定会帮助你。 –

相关问题