Member-only story
How To Design Relationships Between Your Django Models
One-to-One, One-to-Many, and Many-to-Many relationships in Django

Designing the database is one of the most important parts of building a web application. If you’re using a relational database, maintaining proper relationships between the tables is a must.
Each model in a Django application represents a database table. By default, Django models operate on Relational Database Management System (RDBMS). So you need to design your Django models maintaining proper relationships between them.
In this article, we will understand how to create relationships between database tables in general. And then we will see how to implement those relationships in Django models. Let’s get started!
In a relational database system, there are three types of relationships:
- One-to-One relationship
- One-to-Many relationship (or Many-to-One)
- Many-to-Many relationship
Django models support these three types of relationships. Let’s first understand each relationship with examples. Then we will see how to apply them in Django models.
One-to-One Relationship
“A one-to-one relationship means one record of a table is associated with exactly one record of another table.” — fmhelp
A real-life example of a one-to-one relationship can be a country and its capital city. Each country has only one capital city. And each capital city is the capital city of only one country. The relationship can be represented by the following diagram:

Now let’s see how to convert this into a Django model. To establish a one-to-one relationship in Django, the keyword OneToOneField
is used.