Мне не нравится такая логика в шаблоне, поэтому я могу предложить перенести ее в поле зрения.
Обновление контекста передается в шаблон следующим образом:
articles_data = dict()
for article in articles:
# following line is little bit long, but you can rewrite it with regular for loop
# Note, attribute values should be in list
articles_data[article.title] = [attribute.value for attribute in attributes \
if article.supplierID == attribute.SupplierID and article.ItemID = attribute.ItemID]
Когда вы передадите articles_data
в шаблон, вы можете просто сделать:
{% for title, attributes in articles_data.items %}
{{title}}:
{{attributes|join:', '}}
{% endfor %}