One To One Relationship

Let’s learn how to make One-to-One relationships between Django models.

OneToOneField field

This field is used for a One-to-One relationship. To understand how this relationship between models works, we don’t need to add another model. We will use our existing models:

  • Company
  • Employee
  • Projects

Now, the new relationship we are adding is that one project will have only one employee as a Team Lead. Similarly, one employee will be the Team Lead for only one project. This makes it a One-to-One relationship. This relationship is shown in the following illustration:

Get hands-on with 1200+ tech skills courses.