2

I currently have this variable in my template:

{{ product_list.0.image_set.all.0.image.url }}

It successfully gives the url for the first image in the first product in the product list.

I want something like this:

{{ product_list.forloop.counter.image_set.all.0.image.url }}

So that I can get the first image of every image in the product_list in a for loop. But the above code does not work. Is this possible?

1
  • First image of every product in the product_list you mean? Tried this - {{ product_list.all.image_set.0.image.url }} ? Commented Jun 2, 2014 at 23:43

1 Answer 1

3

Do not use a forloop.counter, iterate over product_list object by object:

{% for product in product_list %}
    {{ product.image_set.all.0.image.url }}
{% endfor %}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.