I set up 2 models Article and Taxonomy. Taxonomy is an MPTTModel Subclass.
除一件事外,所有工作都受到罚款: 如果我选择一个没有相关条款的母子的话,就不会展示与儿童节点相关的文章。
因此,我正试图将我的习俗过滤器编码,但我却坐在盘点过滤器上。 我如何过滤这一问询,以显示与儿童相关的所有文章。
class TaxonomyFilter(SimpleListFilter):
"""
Return incremented taxonomy list. Filtering by parent node display all children.
"""
title = ( Index )
parameter_name = node_id
def lookups(self, request, model_admin):
taxos = Taxonomy.objects.all()
leafs = []
for taxo in taxos:
leafs.append((taxo.id,(taxo.name)))
return leafs
def queryset(self,request,queryset):
"""
Filter list by displaying children if parent node has any.
"""
if self.value():
return queryset.filter()
else:
return queryset