I propose chaning 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:
{{{#!django
{% 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>
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/27126>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
Comment (by bmispelon):
PR here: https://github.com/django/django/pull/7157
--
Ticket URL: <https://code.djangoproject.com/ticket/27126#comment:1>
* stage: Unreviewed => Accepted
Old description:
> Currently, `{% regroup %}` returns a list of dictionaries with two key
> (`grouper` and `list`).
>
> I propose chaning 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:
> {{{#!django
> {% 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>
>
> }}}
New description:
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:
{{{#!django
{% 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>
}}}
--
--
Ticket URL: <https://code.djangoproject.com/ticket/27126#comment:2>
* status: new => closed
* resolution: => fixed
Comment:
In [changeset:"61b45dff6be3a2c85adac73acf5fe0de71f9ecda" 61b45dff]:
{{{
#!CommitTicketReference repository=""
revision="61b45dff6be3a2c85adac73acf5fe0de71f9ecda"
Fixed #27126 -- Made {% regroup %} return a namedtuple to ease unpacking.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/27126#comment:3>