How can i check if values of models are the same in django loop?

57 views Asked by At

I've a loop:

{% for addimg in post.addimg_set.all %}
    <p> 
    {{ addimg.execution }}<br>
    {{ addimg.width }} cm x {{ addimg.height }} cm<br>
    {{ addimg.year }}
    </p>
{% endfor %}

I want to display some data as long as they are different. If they are equal i want it only to display once like:

{% if addimg.execution == addimg.execution %}
    {{ addimg.execution }}<br>
{% endif %}

forgive me my python/django still young. Any suggestions?

2

There are 2 answers

0
malisit On BEST ANSWER

You may find your answer in documentation.

Check this out: https://docs.djangoproject.com/en/1.8/ref/templates/builtins/#ifchanged

0
Jingo On

I think you are looking for the {% ifchanged %} template tag.

{% ifchanged addimg.execution %}
    {{ addimg.execution }}<br>
{% endifchanged %}