Kartik
Kartik

Reputation: 65

How we identify repeat value of variable in django templates

IN DJango cms template i want to display track name and course.

                    {% for c in courses %}

                        {% if c.domain|stringformat:"s" == d.domain_nm %}

                            {% if c.track != None %}
                                <h3>{{ c.track }}</h3>
                            {% endif %}

                          {{ c.course_nm }}

                        {% endif %}

                    {% endfor %}

here from courses table "c.track" is heading and course name in list when i add same track in course so it display twice .

Now,i suppose to do that same track name is there so don't print it's track name again i think it has a way that we store {{ c.track }} in list and match current track value with previous track value if same so can't display it ,but the problem is we can't convert {{ c.track }} variable in list in template in django

Is there any another way for do that? pls help !!!! Thanks in adcvance!!!

Upvotes: 1

Views: 137

Answers (1)

Daniel Roseman
Daniel Roseman

Reputation: 600051

This is what the ifchanged tag does.

{% ifchanged c.track %}
    <h3>{{ c.track }}</h3>
{% endifchanged %}

Upvotes: 3

Related Questions