Please help me for coding to create table by use loop.
I need a table like this.
I use python and django in my project. I have problem in 'Additional Cost', I can't complete it because it must merge row by rowspan.
This is my template.html
<table border=1 >
<thead>
<tr>
<th>Import ID</th>
<th>Date</th>
<th>Product</th>
<th>Amount</th>
<th>Cost</th>
<th>Additional Cost</th>
</thead>
<tbody align="center">
{% for imp in import_list %}
<tr>
<td rowspan={{imp.row_span}}><a href="{% url 'edit_import_history' imp.id %}">#{{imp.id}}</a></td>
<td rowspan={{imp.row_span}}>{{imp.import_date}}</td>
{% for imp_pd in importproduct %}
{% if imp_pd.import_id.id == imp.id %}
<td>
{{imp_pd.product_id.product_name}}</td>
<td>{{imp_pd.import_amount}}</td>
<td>{{imp_pd.import_price}}</td>
{% if imp_pd.import_id.row_span > 1 %}
<tr>
</tr>
{% endif %}
{% endif %}
{% endfor %}
</tr>
{% endfor %}
</tbody>
</table>
Ps. imp.rowspan = [count of products in each import id - (count of product in each import - 1)] It should equal count of products in each import id but I don't know which way is better.
example at Import ID #1 have 3 product (A,B,C) if should rowspan 3 but in my solution rowspan is 3+(3-1) = 5 rowspan