Recall & Review
beginner
What is a
OneToOneField in Django?A
OneToOneField creates a one-to-one relationship between two models, meaning each record in one model is linked to exactly one record in another model.Click to reveal answer
beginner
How do you define a one-to-one relationship in Django models?
Use
models.OneToOneField inside a model to link it to another model with a one-to-one relationship.Click to reveal answer
beginner
What is a real-life example of a one-to-one relationship?
A person and their passport: each person has exactly one passport, and each passport belongs to exactly one person.
Click to reveal answer
intermediate
What happens if you try to create two records linked to the same record using a
OneToOneField?Django will raise an
IntegrityError because OneToOneField enforces uniqueness, so only one record can link to the other.Click to reveal answer
intermediate
How do you access the related object in a one-to-one relationship?
You can access the related object using the attribute name defined by the
OneToOneField on the model instance.Click to reveal answer
What does
OneToOneField enforce between two Django models?✗ Incorrect
OneToOneField ensures a strict one-to-one link between two models.Which Django field type would you use to create a one-to-one relationship?
✗ Incorrect
models.OneToOneField is the correct field for one-to-one relationships.If a
OneToOneField is set on model A pointing to model B, how do you access model B from an instance of model A?✗ Incorrect
The related object is accessed directly via the attribute defined by the
OneToOneField.What error occurs if you try to link two records to the same record using a
OneToOneField?✗ Incorrect
Django raises an
IntegrityError because the uniqueness constraint is violated.Which of these is a good example of a one-to-one relationship?
✗ Incorrect
Each student has exactly one ID card, and each ID card belongs to one student.
Explain how to create and use a
OneToOneField in Django models.Think about how two models can be connected so each record matches exactly one record in the other.
You got /4 concepts.
Describe a real-life situation where a one-to-one relationship fits well and how it maps to Django models.
Think about unique pairs in everyday life.
You got /4 concepts.