Many to Many and One to One
ManyToManyField links many rows to many rows, such as posts and tags. OneToOneField links exactly one row to one row, often a user profile.
Example
class Tag(models.Model):
name = models.CharField(max_length=30)
class Post(models.Model):
tags = models.ManyToManyField(Tag, blank=True)
post.tags.add(tag)
post.tags.all()
Tag.objects.filter(post__title="Hello")Exercise
Link many to many.
tags = models.Field(Tag)
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.