I am training myself on Django and working on a movie blog and have issues with my fixtures that I scrape from themoviedb's api. I am wondering the right way to insert a ManyToMany with intermediary model. Here is my current state (removing the useless fields):
class Movie(models.Model):
tmdb_id = models.AutoField(primary_key=True)
original_title = models.CharField(max_length=255)
actors = models.ManyToManyField(Person, through='Actor', related_name="movie_cast")
staffs = models.ManyToManyField(Person, through='Staff', related_name="movie_staff")
class Actor(models.Model):
person = models.ForeignKey(Person, on_delete=models.CASCADE)
movie = models.ForeignKey(Movie, on_delete=models.CASCADE)
role = models.CharField("person's role in a movie", max_length=40)
class Staff(models.Model):
person = models.ForeignKey(Person, on_delete=models.CASCADE)
movie = models.ForeignKey(Movie, on_delete=models.CASCADE)
department = models.CharField(max_length=30)
job = models.CharField("person's job in a movie", max_length=40)
What I am doing now is insert manualy a model.actor or model.staff like this to the fixture. Edit: this is created in a Django command that make the .json, then inserted whith loaddata.
{"model": "blog.actor",
"fields": {
"person": people['id'],
"movie": movie['id'],
"role": people['character'],
}
}
I try to pass this dict or just the additional field to movie.actor field but it needs a int foreign key.
Am I doing right or there is a better way to do this ?
Thanks.