I have a for loop in my django template that outputs a whole bunch of results (each result has a timestamp). I want to print an arbitrary piece of data (for example, <hr />) as soon as the timestamp reaches a certain value, but I only want to print it once.
{% for result in set %} {% if some_time > result.time %} <hr /> {% endif %} {{ result.info }} {% endfor %}
This is fine, except that it will print HR for each result for which the above matches true. I need this to be printed only for the first time.
Sort of:
{% if some_time > result.time and bool_flag %}
Now, since Django does not support variable assignment in its templates, I am losing a bit of what to do. I can come up with several ways to do this (using a template / function class that allows the flag to switch, or, as an alternative, do more processing in the view, but I'm afraid that this will increase the number of database calls and iterations over the data), but I I wonder if there is a nice easy way to "djangoey" do this.
Thanks =)
source share