Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django Many to Many in template

This is my template tag in a forloop

{{ product.feature_set.all.1.value }}

i want to change the number 1 to the forloop.counter. is this posible?

like:

{{
product.feature_set.all.forloop.counter.value
}}

It does not work like that, but is there a way to do this?

like image 226
Harry Avatar asked Jan 24 '26 13:01

Harry


1 Answers

This doesn't make sense. You should be looping through the queryset itself.

{% for feature in product.feature_set.all %}
    {{ feature }}
{% endfor %}
like image 51
Daniel Roseman Avatar answered Jan 27 '26 07:01

Daniel Roseman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!