Я пытаюсь показать разные столбцы (в list_display) в зависимости от выбранного фильтра.
Вот мой код:
# Filter:
class FilterNameFilter(admin.SimpleListFilter):
title = ('FilterName')
parameter_name = 'FilterName'
def lookups(self, request, model_admin):
return (
('xxx', _('xxx 1')),
('yyy', _('yyy 2')),
)
def queryset(self, request, queryset):
if self.value() == 'xxx':
return queryset.filter(c__isnull=False)
if self.value() == 'yyy':
return queryset.filter(d__isnull=False)
# Model:
class pricelist_admin(ModelAdmin):
...
list_display = ('EAN_id', 'Vendor', 'Description', 'DynamicColumn', 'a', 'b', 'c', 'd', 'e')
list_filter = ('Vandor_id__Name', FilterNameFilter)
search_fields = ('EAN_id__Description', 'EAN_id__EAN')
#Dynamic column:
def DynamicColumn(self, obj):
if # ... Here is my code for showing different columns,
# it works fine for other loop's examples, but I don't know
# how to integrate it with "FilterNameFilter" to return desired columns:
return obj.e
else:
return obj.EAN.Description
Есть идеи? Помощь будет очень признателен!