This is an odd question but I'd like to be able to show the same queryset multiple times on my template using different {% for loops %}
, I'm trying to avoid copy pasting each {% for loops %}
.
Let's say I have my views.py like this :
...
chicken = Chicken.objects.filter(id=1)
return render(request, 'chicken.html', {'chicken':chicken}
chicken.html : the example below is the one I'm avoiding.
<!-- {{ egg }} has the same value everywhere -->
{% for egg in chicken %} <!-- has a different index than other loops -->
<p id="egg_1">{{egg}}</p>
{% endfor %}
{% for egg in chicken %}
<p id="egg_2">{{egg}}</p>
{% endfor %}
{% for egg in chicken %}
<p id="egg_3">{{egg}}</p>
{% endfor %}
...x52...
Is there a way to automatise this while having a different index on each loop ?
I'm searching for something like this :
{% for chicken x52 %}
{% for egg in chicken %}
<p id="egg_index">{{egg}}</p> <!-- each with different index -->
{% endfor %}
{% endfor %}