def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['category_list']=Category.objects.filter(parent__isnull=True).annotate(num=Count('products'))
return context
{% for category in category_list %}
<div class="single-category">
<a href="{{category.get_absolute_url}}">
{{category.title}}
{{category.num}}
<span style="color: gray;">
</span>
</a>
</div>
{% endfor%}
我有这样的数据电子0职位0但在儿童类别中,我有两个职位,我想在所有子类别的父类别中显示总帖子数