I'm trying to get a ManyToManyField working with a through
model, which would look something like this:
class DirectorCredit(models.Model):
director = models.ForeignKey(Person, null=False)
movie = models.ForeignKey(Movie, null=True)
tv_show = models.ForeignKey(TVShow, null=True)
ordering = models.IntegerField(default=0)
I then want the Movie
and TVShow
models to be able to access these credits through a ManyToManyField
(or a similar mechanism) like this:
class Movie(models.Model):
....
directors = models.ManyToManyField(Person, through='DirectorCredit')
....
(and the same with TVShow)
Is this sort of structure possible? Would movieObject.directors.all()
fetch me all of the directors with DirectorCredit
entries containing that movie? And would I be able to do the same thing with the TVShow
model?