How do I reference the other object in django models
- by UserZero
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.