row1 = [] row2 = []
categories= Kategoriler.objects.all().filter(parent_id__isnull=True).order_by('id')
for x in categories:
row1.append(x.title)
row2.append(Kategoriler.objects.all().filter(parent_id=x.id).order_by('title'))
zipped = itertools.zip_longest(row1, row2)
for u, y in zipped:
print(">>>>>>>>>>>>>>>", u, "<<<<<<<<<<<<<<<<<<<<")
for q in y:
print(q.title)
context = {'segment': 'categories', "zipped": zipped}
Above code prints as expected in view.py
In templete;
{{ zipped|length }}
{% for u, y in zipped %}
{{ u }}---{{ y.title }}
{% endfor %}
len gives 0, and loop is empty. What's the reason of it?