{% regroup %} is elegantly or more optimized???

On Fri, May 12, 2017 at 5:05 AM, <jorrit...@gmail.com> wrote:

> You can look into the {% regroup %} template tag. It will do what you are
> trying to do more elegantly.
>
>
>
> On Wednesday, May 10, 2017 at 7:40:26 PM UTC+2, Michael Smith wrote:
>>
>> I'm following the latest Tango book and was experimenting with different
>> ways of looping through categories and subcategories to create a list.  I
>> have a 'Category' and 'Page' model, where Page has a foreign key to
>> Category's ID.  To display a list with sub-bullets I simply passed all
>> categories and pages to a template and then looped through Page:
>>
>> <ul>
>>   {% if cats %}
>>     {% for c in cats %}
>>       {% if c == act_cat %}
>>       <strong><li><a href="{% url 'show_category' c.slug %}">{{ c.name
>> }}</a></li>
>>       </strong>
>>       {% else %}
>>       <li><a href="{% url 'show_category' c.slug %}">{{ c.name }}</a>
>>       {% endif %}
>>         {% for p in pages %}
>>           {% if p.category_id == c.pk %}
>>             <ul><li><a href="{{ p.url }} ">{{ p.title }}</li></ul>
>>           {% endif %}
>>         {% endfor %}
>>     {% endfor %}
>>   {% else %}
>>     <li><strong>There are no categories present.</strong></li>
>>   {% endif %}
>> </ul>
>>
>> Is this considered the best way to do such a thing?
>>
>> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/96558026-ac69-4c7c-bb98-cee43dddee82%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/96558026-ac69-4c7c-bb98-cee43dddee82%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>



-- 
att.
Carlos Rocha

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAM-7rO0R5A0UZ38mJKtLRzd_GzdwXVQMDYdrqarhMyNyFFu6Fg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to