What I want to do is quite simple: I have a model which I am running a regroup loop on. Now I want to show the first 4 items of the loop next to each other, and then continue on the next line with the next 4 items until the list is done. If there are no more items, the other cells on the line can stay empty.
I have tried to understand how I can use iterations here, but haven’t been able to figure out how it fits to what I have. Also, I have the idea that it should be possible to do this in a simpler way… Below I copied the code that I have now, which obviously shows the first item of the loop 4 times, then 4 times the second one, etc.
I know there are some similar questions on this website, but I haven’t been able to leverage them to develop a solution for my question. I’m running Python on Google App Engine. Any help is greatly appreciated!
{% regroup communities|dictsort:"in_country" by in_country as community_list %}
{% for in_country in community_list %}
<h2 style="font-size:16px;">{{ in_country.grouper }}</h2>
<table cellspacing="0">
{% for item in in_country.list|dictsort:"name" %}
<tr style="text-align:center;">
<td width="200px" class='community_table'>
<img src="{{ item.image }}" style="height:40px;"><br />
<a href='{{ item.url }}' style="font-size:10px; margin-left:10px;" TARGET = "_blank">{{ item.name }}</a><br />
{{ item.com_type }}<br />
{{ item.in_city }}<br />
</td>
<td width="200px" class='community_table'>
<img src="{{ item.image }}" style="height:40px;"><br />
<a href='{{ item.url }}' style="font-size:10px; margin-left:10px;" TARGET = "_blank">{{ item.name }}</a><br />
{{ item.com_type }}<br />
{{ item.in_city }}<br />
</td>
<td width="200px" class='community_table'>
<img src="{{ item.image }}" style="height:40px;"><br />
<a href='{{ item.url }}' style="font-size:10px; margin-left:10px;" TARGET = "_blank">{{ item.name }}</a><br />
{{ item.com_type }}<br />
{{ item.in_city }}<br />
</td>
<td width="200px" class='community_table'>
<img src="{{ item.image }}" style="height:40px;"><br />
<a href='{{ item.url }}' style="font-size:10px; margin-left:10px;" TARGET = "_blank">{{ item.name }}</a><br />
{{ item.com_type }}<br />
{{ item.in_city }}<br />
</td>
{% endfor %}
</table>
{% endfor %}
1 Answer