Pergunta

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"?

Foi útil?

Solução

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.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top