jeudi 31 octobre 2019

In django, how do you create many to many relationshipd between models

Say i have 3 models (Actor, Movie and Series) defined like this:

class Actor(models.Model):
    name = charField...
    date_of_birth = ...
    filmography = (list of Series and Movie objects)

class Movie(models.Model):
    name = ...
    genre = ...
    cast = (list of Actor objects)

class Series(models.Model):
    name = ...
    no_of_eps = ...
    cast = (list of Actor objects)

How do i make a many to many relationship between 'actor and movie' and 'actor and series' where actor can store a number of movies and tv shows in its filmography field and movie and series can store a number of actors in there respective cast fields.

(Ignore lack of inheritance for movie and series unless it's the only solution)




Aucun commentaire:

Enregistrer un commentaire