Crispy form Change default text shown for ImageField when not empty

34 views
Skip to first unread message

Subodh Nijsure

unread,
Aug 14, 2014, 9:23:45 AM8/14/14
to django...@googlegroups.com
Hello,

I have following field in my model.

photo = models.ImageField(null=True,blank=True,upload_to="product_images")

I have defined the following layout in forms.py for this field, while
using crispy-form

self.fields['photo'].label = "Asset Image"
self.helper.layout = Layout(
'photo',
HTML("""{% if form.photo.value %}
<img height="80"
width="160"
class="pull-left"
src="{{ MEDIA_URL }}{{ form.photo.value }}">
{% endif %}""", ),

Now I can upload images associated with this particular field just
fine. However when I try to update the image I see the following in my
template:

http://i.imgur.com/wcB1JIP.png

Is there any way I can change the layout so that only the browse
button and existing image are shown when the image field is not empty?
In other words, remove the text Currently: product_images/km_2.jpeg
Clear Change:

-Subodh
Reply all
Reply to author
Forward
0 new messages