I have a query in django that:
- gets the current category.
- based on that gets all it’s sub categories
- then make a query to get the articles that are contained in the above sub_categories
My template should be displaying all articles with divisions based on those sub_categories.
How might I do it?
thanks (:
{% for article in articles %}
{% ifchanged article.category %}
<p>{{ article.category }}</p>
{% endifchanged %}
<a href="#" class="item">
<span>{{article.code}}</span>
<span class="large">{{article.description}}</span>
<span>{{article.family_name}}</span>
<span class="small">{{article.last_cost|floatformat:2}}</span>
<span class="small">{{article.sell_price1|floatformat:2}}</span>
<span class="small">{{article.stock|floatformat:2}}</span>
<span class="last">{{article.stock_consignments|floatformat:2}}</span>
</a>
{% endfor %}
You can create a dictionary in your view code, with one entry per category that contains a list of the articles. So it looks something like this:
Will make it much easier for the template code.