I have the following model:

class Document(BaseModel):
     name = models.CharField(max_length=150,blank=True)
     type = models.ForeignKey(DocumentType)
     description = models.TextField(blank=True)
     file = 
models.FileField(upload_to="data/documentation/document/%Y/%m/%d",blank=True)


And suppose, I have the file "/tmp/test.txt" in my local filesystem.

How could I add this file to a new model usign the django shell?


I've tryed by instantiating a new Document, and then doing:

object.file = File(open("/tmp/test.xt"))
object.save()


But this gives me the following error:


Traceback (most recent call last):
   File "./migrate.py", line 175, in <module>
     object.save()
   File "/home/msurdi/proyecto/it/../it/apps/__init__.py", line 44, in save
     super(BaseModel,self).save(*args,**kwargs)
   File "/usr/lib/python2.5/site-packages/django/db/models/base.py", 
line 408, in save
     self.save_base(force_insert=force_insert, force_update=force_update)
   File "/usr/lib/python2.5/site-packages/django/db/models/base.py", 
line 474, in save_base
     values = [(f, f.get_db_prep_save(raw and getattr(self, f.attname) 
or f.pre_save(self, True))) for f in meta.local_fields]
   File 
"/usr/lib/python2.5/site-packages/django/db/models/fields/files.py", 
line 188, in pre_save
     file = super(FileField, self).pre_save(model_instance, add)
   File 
"/usr/lib/python2.5/site-packages/django/db/models/fields/__init__.py", 
line 179, in pre_save
     return getattr(model_instance, self.attname)
   File 
"/usr/lib/python2.5/site-packages/django/db/models/fields/files.py", 
line 139, in __get__
     (file.__class__, self.field.attr_class), {})
TypeError: Cannot create a consistent method resolution
order (MRO) for bases File, FieldFile



Thanks a lot.



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to