Recall & Review
beginner
What is a ManyToManyField in Django?
A ManyToManyField in Django is a field type used to create a many-to-many relationship between two models. It allows each record in one model to be linked to multiple records in another model, and vice versa.
Click to reveal answer
beginner
How does Django store many-to-many relationships in the database?
Django creates an automatic intermediate table (called a join table) that holds pairs of IDs from the two related models to represent the many-to-many links.
Click to reveal answer
beginner
How do you add related objects to a ManyToManyField in Django?
You use the add() method on the ManyToManyField manager. For example, book.authors.add(author) links an author to a book.
Click to reveal answer
intermediate
Can you customize the intermediate table in a ManyToManyField?
Yes, by defining an explicit through model, you can add extra fields or control the intermediate table used for the many-to-many relationship.
Click to reveal answer
intermediate
What happens if you delete an object involved in a ManyToManyField?
Django automatically removes the related entries in the intermediate table, so the many-to-many links are cleaned up without deleting the related objects themselves.
Click to reveal answer
What does a ManyToManyField represent in Django?
✗ Incorrect
A ManyToManyField creates a many-to-many relationship allowing multiple records on both sides to be linked.
How does Django handle the database structure for ManyToManyField?
✗ Incorrect
Django automatically creates an intermediate table to store pairs of related object IDs.
Which method is used to add related objects to a ManyToManyField?
✗ Incorrect
The add() method is used on the ManyToManyField manager to link related objects.
What is the purpose of the 'through' parameter in ManyToManyField?
✗ Incorrect
The 'through' parameter lets you define a custom model for the intermediate table to add extra fields or behavior.
What happens to many-to-many links when a related object is deleted?
✗ Incorrect
Django removes the links in the intermediate table but does not delete the related objects.
Explain how ManyToManyField works in Django and how it manages relationships in the database.
Think about how two models can be connected many times each way.
You got /4 concepts.
Describe how you can customize the intermediate table in a ManyToManyField and why you might want to do that.
Consider cases where you want to store more info about the connection itself.
You got /4 concepts.