I try to get the data in my models "Machines" and then need to get Additional information form other table related to each machine. I try bellow code in views.py and render it to specified html page.
def allmachinesLOGO(request):
machines=Machine.objects.all()
c=""
for m in machines:
if m.tb_order_set.filter(status="2").exists():
c="2"
else:
c="0"
context ={'machines':machines,'condition':c}
return render(request,'pline/machineslogos.html',context)
{% if condition == "2" %}
<h4> working</h4>
<img class="btn-circle" style="width: 15px" src="{% static 'images/icons/icons8-green-circle-48.png' %}" alt="image" />
{% else %}
<h4>stop</h4>
{{ condition }}
<img class="btn-circle" style="width: 15px" src="{% static 'images/icons/icons8-red-circle-48.png' %}" alt="image" />
{% endif %}
what's the correct way to pass loop from views.py to template in Django
m.tb_order_set.filter(status="2").exists()?