tags:

views:

281

answers:

1

Hi,

I have a model with a FileField which is shown below. I use this model in a model form.

receipt  = models.FileField(upload_to='receipt/%m-%Y/', max_length=255)

I can save the object and the receipt field contains the file url.

Now when I present this object with the model form the file url is not presented, instead a message "no file chosen" is presented.

This is the html template I m using for the form:

<table  cellspacing="5">
 {{ cash_expenditure_form.as_table }}
</table> 

and the form that I'm using:

class CashExpenditureForm(forms.ModelForm):

class Meta:
    model = CashExpenditure
    exclude = ('project','paid', 'paid_check','invoice','cash_expenditure_selection')

When I check this object in the admin the field url is presented as expected. Thus I think something is missing in the html form template.

Solution:

AdminFileWidget does the trick ;-) easy as always..

A: 

I'm not sure you can pre-fill file selection field.

The file input type creates a field through which users can upload files from their local computer or network. The VALUE attribute specifies the name of the initial file, but it is typically ignored by browsers as a security precaution. The ACCEPT attribute gives a comma-separated list of media types accepted, allowing the browser to filter out inappropriate files. Current browsers generally ignore the ACCEPT attribute.

http://www.htmlhelp.org/reference/html40/forms/input.html

WooYek
Actually it is done in the admin. I'm just searching a way to do it like in the django admin.
Tom Tom
I'm just searching a way to do it like in the django admin. In the admin a href field is presented with the actual value and an "empty" select file button. I'm just searching the way to accomplish this in django.
Tom Tom
Agreed - this is bad user feedback. Even if the upload is successful, the presence of that text makes it look like it was not.
shacker