CARVIEW |
Select Language
HTTP/2 200
server: nginx
content-type: text/html;charset=utf-8
cache-control: must-revalidate
expires: Fri, 01 Jan 1999 00:00:00 GMT
set-cookie: trac_form_token=a1b062ea359ea68871f54b0d; HttpOnly; Path=/; Secure
set-cookie: trac_session=b9200fac1fdb2cf647cc023c; expires=Tue, 28 Oct 2025 20:28:01 GMT; HttpOnly; Path=/; Secure
strict-transport-security: max-age=31536000; includeSubDomains; preload
permissions-policy: interest-cohort=()
x-content-type-options: nosniff
x-frame-options: SAMEORIGIN
x-xss-protection: 1; mode=block
accept-ranges: bytes
via: 1.1 varnish, 1.1 varnish
date: Wed, 30 Jul 2025 20:28:01 GMT
x-served-by: cache-fra-etou8220063-FRA, cache-bom-vanm7210035-BOM
x-cache: MISS, MISS
x-cache-hits: 0, 0
x-timer: S1753907282.554961,VS0,VE180
vary: Accept-Encoding
CookBookTemplateTagRegroup – Django
Back to Top
Django
The web framework for perfectionists with deadlines.
Issues
CookBook - Template tag Regroup
django version : 0.91
If you need to group a list of objects by a choice (eg, field has choices = CATEGORY_CHOICES), here is the trick.
The Model:
CATEGORY_CHOICES = ( (1, 'Entrées'), (2, 'Poissons et crustacés'), (3, 'Viandes et volailles'), (4, 'Légumes et accompagnements'), (5, 'Desserts'), (6, 'Boissons'), (8, 'Autres'), ) class Recette(meta.Model): [...] categorie = meta.SmallIntegerField(choices = CATEGORY_CHOICES)
And here is the regroup
tag in action. The thing is that you don't want to display the category
number, but its corresponding name. (e.g not '1' but 'Entrées').
The Template:
{% regroup recettes by categorie as grouped %} <ul> {% for group in grouped %} <li>{{ group.list.0.get_categorie_display }} <ul> {% for item in group.list %} <li>{{ item }}</li> {% endfor %} </ul> {% endfor %} </ul>
Last modified
19 years ago
Last modified on Mar 3, 2006, 1:29:03 AM
Note:
See TracWiki
for help on using the wiki.
Download in other formats:
Django Links
Learn More
Get Involved
Follow Us
- Hosting by In-kind donors
- Design by Threespot &
© 2005-2025 Django SoftwareFoundation unless otherwise noted. Django is a registered trademark of the Django Software Foundation.