2

In my view I create a formset of photos belonging to a specific article, this works brilliantly, and I am able to render and process the forms. However for the image field I would like to display the already uploaded image. Normally I would access the path through the instance form.instance.image.get_thumbnail_url however that doesn't work for the forms in my modelformset - how can i access the instance?

...
article = get_object_or_404(Article, pk=article_id)
PhotoFormSet = modelformset_factory(Photo)
    formset = PhotoFormSet(queryset=Photo.objects.filter(articles=article_id))
...

...
{% for form in formset.forms %}
     {{ form.instance.image.get_thumbnail_url }}
{% endfor %}
...

1 Answer 1

2

Not sure, but it may be that you don't need instance:

{% for form in formset.forms %}
     {{ form.image.get_thumbnail_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.