Wednesday, May 2, 2012

Upload file and primary key - double save

Hi all,

I'm developing a site where the object Project is referenced by zero or more objects Image, say basically

-------- CODE --------------------------------------------

class Projects(models.Model):
 pass

class Image(models.Model):
 project = models.ForeignKey(Project)

---------------------------------------------------------------

I would like to have all images served as 001.jpeg, 002.jpeg and so on, and I'd prefer to host them locally in a per-project subdirectory of my media storage path.

I can implement a new save() to create a media subdirectory called with a name containing the Project PK.

How can I move all images (previously saved in a directory specified in Image's upload_to parameter) to the new directory?
Is the Project's save() the correct place to do this?

Thank you in advance

Leo

--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment