0

views.py

def manage_photo(request, obj_id):
    form = MediaFileForm(instance=obj)
    if request.method == "POST":
        # Some actions here
        # ...

    return render(request, 'manage_photo.html', {'form': form,})

I would like to display an image thumbnail next to its form field on the form page. For that purpose I use easy-thubmnails module. I would like to write something like this in template:

<img src="{{ form.image|thumbnail_url:'small' }}">

But I can't, because {{ form.image }} is not a File object, which thumbnail_url filter takes as an argument.

I would appreciate any suggestion.

Petteri H
  • 11,779
  • 12
  • 64
  • 94
Vlad T.
  • 2,568
  • 3
  • 26
  • 40

2 Answers2

1

Since you initialized the form with an instance, you can access that instance: form.instance.image.

Daniel Roseman
  • 588,541
  • 66
  • 880
  • 895
-1

It takes the form form.field.value

<img src="{{ form.image.value|thumbnail_url:'small' }}">
Andrew Sledge
  • 10,163
  • 2
  • 29
  • 30