Amber Chen
Amber Chen

Reputation: 993

Template for loop if the current iteration is different from the previous iteration

I want to have

{% for user_id, x, y in information %}
    {% if it is the first time that user_id is different from the previous iteration %}
        do something
    {% elseif user_id is different from the user_id in the previous iteration %}
        do something
    {% endif %}

Can anyone help. Thanks!!!

Upvotes: 0

Views: 41

Answers (1)

Jingo
Jingo

Reputation: 3240

You are looking for {% ifchanged %}. Have a look here: https://docs.djangoproject.com/en/dev/ref/templates/builtins/#ifchanged

Upvotes: 2

Related Questions