views:

281

answers:

1

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 %}
...
+2  A: 

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

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