i need to display some data from the DB.
I need to display the OrderItem and all related OrderProperties (with a FK)
In the view i do something like:
orderitems = OrderItem.objects.all().filter(order=order)
properties = []
for item in orderitems:
a = OrderItemDetail.objects.all().filter(orderitem=item)
b = []
for x in a:
c = [x.detail.property.name, x.detail.value, x.detail.price, x.detail.detail_price_unit]
b.append(c)
properties.append(b)
At the end I have a list of properties that i need then in the template I use them:
# orderitems loop - displaying item detail
# displaying the properties
{% for prop in properties %}
{% for x in prop %}
<big><b>{{x.0}}</b>: {{x.1}} (+{{x.2}}
{% if x.3 == "m" %}
€/MQ
{% endif %}
{% if x.3 == "p" %}
%
{% else %}
€
{% endif %}
)</big><br />
{% endfor %}
{% endfor %}
That should produce an output like: color: red (+0,0 € )
All works fine but when there are 2 or more orderitems i get each property printed in each record (I would like to display only the properties related to the current item)
It wold be quite easy if I could perform the query in the loop (retrieving only the properties that i need to display in that loop cycle). Yeah, I could create the html element in python, but since I’m using a template engine it seems pretty idiot.
Do you know any way to do that?
PS. i know variable names are meaningless but I need something short while testing
If I understand correctly, you need this.
In view:
It template: