別のフィルタで行われた現在の選択に応じて、1つのフィルタ変更のプロンプトを表示しようとしています。私は、AttributeFilterに渡されたAttributeCategoryFilterの現在選択されている値を取得する方法についてはかなり失われています。私はDjango 1.4-devを使用しています。この目的でRelatedFieldListFilterを使用するべきかどうかを調べようとしています。これらの機能は、まだ野生の中に浮遊している例はないほど若いです(m)。現在のフィルタ選択をDjangoの別のカスタムSimpleListFilterに渡す
class AttributeCategoryFilter(SimpleListFilter):
title = _('Attribute Category')
parameter_name = 'attribute_category'
def lookups(self, request, model_admin):
attributes = Attribute.objects.filter(parent_attribute=None)
prompts = []
for attribute in attributes:
prompts.append((attribute.title, _(str(attribute.title))))
return prompts
def queryset(self, request, queryset):
if self.value():
return queryset.filter(attribute__category=self.value())
else:
return queryset
class AttributeFilter(SimpleListFilter):
title = _('Attribute Title')
parameter_name = 'attribute_title'
def lookups(self, request, model_admin):
desired_category = # Needs to be a reference to the selected value in the AttributeCategoryFilter above
attributes = Attribute.objects.filter(category=desired_category).exclude(parent_attribute=None)
prompts = []
for attribute in attributes:
prompts.append((attribute.title, _(str(attribute.title))))
return prompts
def queryset(self, request, queryset):
if self.value():
return queryset.filter(attribute__title=self.value())
else:
return queryset
class ValueAdmin(admin.ModelAdmin):
list_display = ('package', 'attribute', 'presence', 'text', 'modified', 'created')
list_filter = ('package', AttributeCategoryFilter, AttributeFilter, 'presence',
'attribute__admin_approved', 'attribute__dtype', 'modified')
search_fields = ('package', 'attribute', 'text')
list_display_links = ('package',)
list_editable = ('presence', 'text')
list_per_page = 20000
admin.site.register(Value, ValueAdmin)
1つの選択肢は、要求から取得することです。 –