I have a many to one relationship in Django: Model A and model B.
I need to output a table where the objects are ordered and grouped by names
Name Amount
======================
A name 200
300
500
Another name 200
30
450
15
The model B has a foreign key to model A, so I need to print all the model B objects and group them by the foreign key.
I know I can accomplish this with the rowspan html attribute and the regroup filter in Django, but I'm not sure how to write the template.
Normally I could just create output all the objects, but I don't want to write the name in every row. So I need to group them.
<table>
<thead><tr><th>Name</th><th>Amount</th></tr></thead>
<tbody>
{% for obj in object_list %}
<tr>
<td>{{ obj.name }}</td>
<td>{{ obj.amount }}</td>
</tr>
{% endfor %}
</tbody>
</table>