We have a collection of products . Each product has several prices for different sites product.prices . There is also a collection with sites sites . The task: to form a table, where the row is the item, the column is the site. In the cell - the price corresponding to each site.
Наименование | Цена сайта 1 | Цена сайта 2 | Цена сайта 3 We try to display the table:
<table class="table"> {% for product in products %} <tr> <td>{{ product.name }}</td> {% for site in sites %} {% for price in product.prices %} {% if price.site == site %} <td>{{ price.price }}</td> {% endif %} {% endfor %} {% endfor %} </tr> {% endfor %} </table> The problem is that the product does not always have prices for each of the sites. And in such cases, the lines are shifted to the left. How to implement a table without moving rows?