OneToOneField for one-to-one
📖 Scenario: You are building a simple Django app to store user profiles. Each user has exactly one profile with extra information.
🎯 Goal: Create two Django models: User and Profile. Link them with a one-to-one relationship using OneToOneField.
📋 What You'll Learn
Create a
User model with a username fieldCreate a
Profile model with a bio fieldAdd a
OneToOneField in Profile linking to UserSet
on_delete=models.CASCADE for the OneToOneFieldUse exact field and model names as specified
💡 Why This Matters
🌍 Real World
One-to-one relationships are common when you want to extend user information without changing the original user model.
💼 Career
Understanding OneToOneField is essential for Django developers building user profiles, settings, or linked data models.
Progress0 / 4 steps