How do I reference the other object in django models

Posted by UserZero on Stack Overflow See other posts from Stack Overflow or by UserZero
Published on 2011-01-12T10:51:07Z Indexed on 2011/01/12 10:53 UTC
Read the original article Hit count: 184

Filed under:

Hi, first post here.In Django, I want to have many files be associated with a particular model, so I'm doing a seperate model called files and have model 'A' 'have many' files. But I want my files to be saved in director named by model 'A'. So For example I want something like this:

class Show(models.Model):
     name = models.CharField()
     showfolder = models.FilePathField()

class Episode(models.Model):
     show = models.ForeignKey(Show)
     name = models.CharField()
     files = models.ManyToManyField(mp3)

class Mp3(models.Model):
     file = FileField(upload_to=Episode.show.showfolder)

So hopefully that last line expresses what I WANT it to do(get the folder name from Show object associated with the episode). The question is how would I really write that?(besides jumping through hoops in the controller.)

Thanks.

© Stack Overflow or respective owner

Related posts about django