Opened 19 years ago
Closed 19 years ago
#1575 closed defect (invalid)
REGROUP tag makes two groups with the same value
Reported by: | Owned by: | Adrian Holovaty | |
---|---|---|---|
Component: | Template system | Version: | 0.91 |
Severity: | normal | Keywords: | regroup tag |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
I'm using a generic view (haven't tested with a custom view) and sqlite as backend.
The problem is that the regroup tag isn't working properly, as it is creating two groups with the same grouper value.
When I create the items in a table and use the grouper tag, it groups in the order inserted in the table, unless I specifically use an extra_lookup_kwargs.order_by option.
I think I'll explain better with an example:
I create a table with the columns Col1 and Col2
I create, in the following order the items:
-Val1, 1
-Val2, 1
-Val3, 2
-Val4, 1
Then I pass this table a generic view and use the following in the template:
{% regroup object_list by Col2 as grouped %}
{% for group in grouped %}
<br>Grouper: {{group.grouper}}
{% for equipe in group.list %}
- {{equipe.nome}}<br>
{% endfor %}
{% endfor %}
It returns me the following:
Grouper: 1
- Val1
- Val2
Grouper: 2
- Val3
Grouper: 1
- Val4
Change History (3)
comment:1 by , 19 years ago
comment:2 by , 19 years ago
I think it works just as intended. From Django documentation:
Note that {% regroup %} does not work when the list to be grouped is not sorted by the key you are grouping by! This means that if your list of people was not sorted by gender, you'd need to make sure it is sorted before using it, i.e.:
{% regroup people|dictsort:"gender" by gender as grouped %}
comment:3 by , 19 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
Oh, {% regroup %
}, how do I love thee? Let me count the ways...
Sorry, I didn't know the HTML was used and didn't see the Preview button. Here's the post with the correct formatting:
I'm using a generic view (haven't tested with a custom view) and sqlite as backend.
The problem is that the regroup tag isn't working properly, as it is creating two groups with the same grouper value.
When I create the items in a table and use the grouper tag, it groups in the order inserted in the table, unless I specifically use an extra_lookup_kwargs.order_by option.
I think I'll explain better with an example:
I create a table with the columns Col1 and Col2
Then I create, in the following order the items:
Then I pass this table to a generic view and use the following in the template:
It returns me the following: