[Answer]-Django modeling with filmography

1👍

models.py

class Person(models.Model):
   name = models.TextField()

class Film(models.Model):
   name = models.TextField()
   year = models.IntegerField()
   actors = models.ManyToManyField('Person')

and then access the film actors using the following command

#first get the film from db
f = Film.objects.all()[0] #get the first Film entry
actors = f.actors.all()
👤Bit68

Leave a comment