Reputation: 221
I want to create a list filter in django 1.5 is related to my field so I can not use SimpleListFilter as in the documentation.
I need to do this for reasons of user permissions
i have this
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))
remains unchanged lookups as if he had not cast any changes to the filter
Upvotes: 2
Views: 3494
Reputation: 221
lookups method is noy used by RelatedFieldListFilter class in admin package, the init method set
self.lookup_choices = field.get_choices(include_blank=False)
I override the init method in my class
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',)
....
Upvotes: 3