views:

46

answers:

1

Possible Duplicate:
How to assign a local file to the FileField in Django?

I was trying to assign a file from my disk to the FileField, but I have this error:

AttributeError: 'file' object has no attribute 'open'

My python code:

pdfImage = FileSaver()
myPdfFile = open('mytest.pdf')
pdfImage.myfile.save('new', myPdfFile)

and my models.py

class FileSaver(models.Model):

    myfile = models.FileField(upload_to="files/")

    class Meta:
        managed=False

Thank you in advance for your help

A: 

See http://www.nitinh.com/2009/02/django-example-filefield-and-imagefield/. You need to pass save a Django request.

katrielalex