Recall & Review
beginner
What is a ForeignKey in Django models?
A ForeignKey creates a many-to-one relationship between two models. It means each record in the model with the ForeignKey points to one record in another model, like a child pointing to a parent.
Click to reveal answer
beginner
Explain ManyToManyField in Django models.
ManyToManyField creates a many-to-many relationship. It means records in one model can relate to many records in another model, and vice versa, like friends who can have many friends.
Click to reveal answer
beginner
What does OneToOneField represent in Django?
OneToOneField creates a one-to-one relationship between two models. Each record in one model matches exactly one record in another, like a person and their unique passport.
Click to reveal answer
intermediate
How does Django handle reverse relationships automatically?
Django automatically creates reverse relationships so you can access related objects from either side. For example, from a parent you can get all children without extra code.
Click to reveal answer
intermediate
Why use related_name in Django model relationships?
related_name sets the attribute name for reverse lookups. It helps avoid clashes and makes code clearer when accessing related objects from the other side.
Click to reveal answer
Which Django field type would you use to link a blog post to a single author?
✗ Incorrect
A ForeignKey links many posts to one author, representing a many-to-one relationship.
If you want to model students and courses where each student can take many courses and each course can have many students, which field is best?
✗ Incorrect
ManyToManyField models many-to-many relationships like students and courses.
What does OneToOneField ensure in Django models?
✗ Incorrect
OneToOneField ensures a strict one-to-one link between two records.
What is the purpose of the related_name attribute in Django relationships?
✗ Incorrect
related_name defines the attribute name used to access related objects from the reverse side.
How can you access all related objects from the reverse side of a ForeignKey?
✗ Incorrect
Django creates a reverse attribute named by related_name or a default to access related objects.
Describe the three main types of model relationships in Django and give a simple real-life example for each.
Think about parents and children, friends, and unique pairs like person and passport.
You got /4 concepts.
Explain how Django's related_name helps when working with model relationships and why it is useful.
Consider how you access related objects from the other side.
You got /4 concepts.