I've got the following situation in this system: Each category of products has many subcategories, and each subcategory has many products under it. I'm trying to make a product searh, which returns a list, and in my template, I show an overview of the results, like this:
Cellphones
Dumbphones (2 results)
Smartph开发者_如何学Cones (3 results)
Monitors
CRT (1 result)
LCD (3 results)
I'm my template I have only the list of products. I've tryed many combinations of nested regroups, without success. Any ideas?
You can try something like this:
<div>
...
{% regroup results|dictsort:"subcategory.category" by subcategory.category as categories %}
<ul>
{% for category in categories %}
<li>{{ category.grouper }}
{% regroup category.list|dictsort:"subcategory" by subcategory as subcategories %}
<ul>
{% for subcategory in subcategories %}
<li>{{ subcategory.grouper }}
<!--The same way you can render a subcategory.list which is the prosucts list-->
</li>
{% endfor %}
</ul>
</li>
{% endfor %}
</ul>
acceptance_report.company as companies %}
...
</div>
精彩评论