Comparison of queryset and list using template tags in Django

I have a list and a queryset that always consists of the same number of objects.

query = object1, object2, object3  list = ['true', 'false', 'true'] 

I would like to always show my user object when the in list is true.

In my case, the user should see object1 and object3 from query (because the first and last item on the list is true).

I tried it:

{% for object in query %} <!-- Show all objects in query -->   {% if list.forloop.counter == 'true' %} <!-- get element from list and check if true -->     {{ object.name }} <-- Show my object name from query if the equation is true -->   {% endfor %} {% endfor %} 

But mine {{ forloop.counter }} does not work properly in markup. How can I get the expected result?

Add Comment
0 Answer(s)

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.