0

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?

benwad
  • 6,414
  • 10
  • 59
  • 93

1 Answers1

0

It should work, but it is not great solution. The reason for that is that you can by mistake put both movie and tv show into one DirectorCredit object.

Consider making that relation using gM2M.

GwynBleidD
  • 20,081
  • 5
  • 46
  • 77