3
I have two tables, in the example (any) of the figure below
i have the table Paises
and the table Energia
Setting a third table in Django I would have something with the fields
pais, energia, valor
Áustria, Carvão, 3.6
Áustria, Ciclo combinado de gás, 3.4
and so on.
Question: How I would mount this table in the template as it is in the image?
Edited:
@mgibsonbr I adapted to my model, see the code below.
def quotation_list(request):
stores = list(Store.objects.all())
products = list(Product.objects.all())
# indice
index_store = {store.id: index for index, store in enumerate(stores)}
index_product = {product.id: index for index,
product in enumerate(products)}
# dados para o template
cabecalho = ["Lojas"] + [store.store for store in stores]
linhas = [([product.product] + [None for store in stores])
for product in products]
for pev in Quotation.objects.all():
linhas[index_store[pev.store_id]][
index_product[pev.product_id]] = pev.price
But the following mistake.
Alias, how do I return the items in context to render on the page? return
.
What are your models? Country and Energy? There is no relationship between these two models?
– ppalacios