On 27 July 2010 17:51, Wadim <[email protected]> wrote:
> Hello.
> I have a list that i want to present in a table.
> Each row should have 5 items.
> For now i create the function that returns me new grouped list, that i
> use later in a template.
> def groupListByRow(list):
> cnt=0
> rows=[]
> while cnt<len(list):
> row=[]
> for x in range(5):
> if cnt<len(list):
> row.append(list[cnt])
> else:
> row.append(None)
> cnt+=1
> rows.append(row)
> return rows;
> is there better way to do this? May be it is possible to do it inside
> template?
> Thanks
>
Hi Wadim
You could easily do this in the template with if tag:
<table>
<tr>
{% for value in list %}
{% if value.counter1|divisibleby:"5" %}
<td>{{value}}</td>
</tr>
<tr>
{% else %}
<td>{{value}}</td>
{% if value == list|last %}
</tr>
{% endif %}
{% endif %}
{% endfor %}
</table>
I think that's right, it's off the top of my head so use with caution.
Cheers,
Dan
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>
--
Dan Hilton
============================
www.twitter.com/danhilton
www.DanHilton.co.uk
============================
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.