I am using Django 1.4 and I have a query that brings several data from the db, including one that can have 3 different values (type). Depending on this data I make a conditional and calculate some values (accommodation and diet) to send to the template. If I do it with only one line in the data it works well, the problem is when I have several lines in which if I respect the data that comes in the recordset (name, date and type) but in the fields that calculates puts me in all lines the same.
This is what I want.
nombre tipo mes alojamiento dieta
nombre_1 1 enero 50 45
nombre_2 2 febrero 60 80
Where:
- accommodation = days * amount_hotel --- days depend on type.
- diets = days * amount_diet ---- the two values depend on the type.
This is what I have.
nombre tipo mes importe_noche importe_dieta
nombre_1 1 enero 60 80
nombre_2 2 febrero 60 80
I've tried it with aggregate
, but it gives me an error because the data to be calculated is not in the database.