ManyToManyField and Through Models
Connect records both ways with extra data.
Both Sides Have Many
Sometimes each side links to many of the other: a post has many tags, a tag marks many posts. That is a many-to-many relationship.
Declaring ManyToManyField
Add a ManyToManyField pointing at the other model. Django handles the link from both directions automatically.
class Post(models.Model):
tags = models.ManyToManyField(Tag)All lessons in this course
- ForeignKey and on_delete
- ManyToManyField and Through Models
- OneToOneField for Profiles
- related_name and Reverse Lookups