Question

So I have a ModelForm which is using an ImageField, which works as expected for both inserts and updates. I also have a widget implemented to display a thumbnail for the image if the form is bound. The issue I am having is the file path is still being displayed (along with the thumbnail). How can I override this URL such that it is not rendered as well as the label "Currently"?

Was it helpful?

Solution

The attributes responsible for rendering the current file path to an instantiated form us found in: forms.widgets.ClearableFileInput()

Override ClearableFileInput()'s render method. In my case I changed

substitutions['initial'] = (u'<a href="%s">%s</a>'
                                    % (escape(value.url),
                                       escape(force_unicode(value))))

to

substitutions['initial'] = (u'%s <br />'
                                %(escape(force_unicode(os.path.basename(value.url)))))

Doing this removed the path to the current file and displays just the file name, without a link.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top