我想在django 1.5中创建一个列表过滤器与我的字段相关,所以我不能像文档那样使用SimpleListFilter。
出于用户权限的原因,我需要这样做
我有这个
class Stores_Contactos_Stores_ListFilter(RelatedFieldListFilter):
title = _('Por Tiendas')
parameter_name = 'store'
def lookups(self, request, model_admin):
return (
('80s', _('in the eighties')),
('90s', _('in the nineties')),
)
class Store_Contacts_Admin(admin.ModelAdmin):
list_filter = ('date_create', ('store', Stores_Contactos_Stores_ListFilter))
保持未更改的查找,就好像他没有对过滤器进行任何更改
答案 0 :(得分:3)
lookups方法, init 方法集
self.lookup_choices = field.get_choices(include_blank=False)
我覆盖了班级
中的 init 方法def __init__(self, field, request, params, model, model_admin, field_path):
super(Stores_Contactos_Stores_ListFilter, self).__init__(
field, request, params, model, model_admin, field_path)
if request.user.is_superuser:
self.lookup_choices = Stores.objects.values_list('store', 'store__name',)
....