-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

Community
  • 1
  • 1
Leodom
  • 471
  • 1
  • 5
  • 7
  • Isn't this essentially the same question that you asked an hour ago? http://stackoverflow.com/questions/3501588/how-to-assign-a-local-file-to-the-filefield-in-django Is there any specific reason why you are posting it again as a new question? – Manoj Govindan Aug 17 '10 at 12:02
  • Don't repost identical questions an hour apart. – Katriel Aug 17 '10 at 12:10

1 Answers1

0

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

Katriel
  • 120,462
  • 19
  • 136
  • 170