[EMAIL PROTECTED] wrote: > Hello, > > I have a site that offers a bunch of appartments for rent. Each of > these rentals has a image gallery showing the look&feel of that place. > My models currently look like this: > > class Photo( models.Model ): > name = models.ImageField( upload_to='rentals' ) > > class Rental( model.Model ): > gallery = models.ManyToManyField( Photo ) > > But after about 20 rentals with about 10 photo's each, it get very > hard to search to the m2m field to find the correct photo. Also all > photo's are stored in the same directory (/media/rentrals) (including > thumbnails), which gets really confusing. > > I have tried placing with references between Photo and Rental, also > tried a 3rd class "Gallery" as binding class, but that all does not > really do what I want. > > Also that cannot be unique, because for a blog I can imagine the same, > that you only what to see images you uploaded for a specific blog, so > perhaps someone has already solved this. > > What I would like to have a that each rental item has its own, unique, > gallery, that also stores the photo's in a seperate directory that > maches the id of the rental item. How whould I go about this ?
If a gallery is unique to a rantal, why use a n:m relationship? You should be able to use a 1:m if each photo is associated with exactly one rental. As to putting the images in rental-specific sub-directories, can you make the association from photo to rental explicit and do this? class Photo( models.Model ): def __init__(self): Super(Photo, self).__init__() self.name.fields.upload_to = self.name.fields.upload_to \ + '/%d/' % self.id or something along those lines. L. --~--~---------~--~----~------------~-------~--~----~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---