How to access an instance of forms in django modelformset

In my opinion, I create a set of photos related to a specific article, it works brilliantly and I can handle and manipulate forms. However, for an image field, I would like to display the already loaded image. I used to access the path through the instance form.instance.image.get_thumbnail_url

, however this doesn't work for forms in my modelset - 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 %}
...

      

+2


source to share


1 answer


Not sure, but maybe you don't need instance

:



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

      

+2


source







All Articles