Hello,

 here is my model:

 Class Photo( models.Model ):
   photo = models.ImageField( upload_to="mydir/" )

 This class is going to be used to save Images in a gallery that are
uploaded thru a zip file, so first I verify if the zip file is valid, then I
extract all of the files to a gallery specific directory, after that I
iterate thru the extracted files and associate them with the photo field of
my model. This is what I am doing on the save() method of this model:

----
                for filename in os.listdir( settings.MEDIA_ROOT +
"/images/galerias/" + self.slug ):
                        file = open( settings.MEDIA_ROOT + "/mydir" +
filename, 'rb' )

                        photo = Photo( )
                        photo.photo.file = file
                        photo.photo.save( filename, file, save = False )
----

However, I always get the following error:
----
*** ValueError: The 'foto' attribute has no file associated with it.
----

 Whats the correct approach for doing such a thing? I want to be able to
associate a file from the disk with an specific ImageField field of my
model.
 Any ideas?

Thanks in advance,
Victor Lima

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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