Opened 8 years ago
Closed 8 years ago
#27126 closed Cleanup/optimization (fixed)
Use `namedtuple` in result of `{% regroup %}`
Reported by: | Baptiste Mispelon | Owned by: | nobody |
---|---|---|---|
Component: | Template system | Version: | 1.10 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
Currently, {% regroup %}
returns a list of dictionaries with two key (grouper
and list
).
I propose changing that to return a namedtuple
with the same fields.
This should be backwards-compatible because attribute access and key access inside template uses the same syntax.
The added benefit would be that you could now write:
{% regroup places by country as country_list %} <ul> {% for country, cities in country_list %} <li>{{ country }} <ul> {% for city in cities %} <li>{{ city.name }}: {{ city.population }}</li> {% endfor %} </ul> </li> {% endfor %} </ul>
Change History (3)
comment:1 by , 8 years ago
comment:2 by , 8 years ago
Description: | modified (diff) |
---|---|
Triage Stage: | Unreviewed → Accepted |
Note:
See TracTickets
for help on using tickets.
PR here: https://github.com/django/django/pull/7157