ForeignKey and ManyToMany relationships

Django expresses relationships between models with ForeignKey (many-to-one), ManyToManyField (many-to-many) and OneToOneField. A ForeignKey creates a foreign key column and a reverse accessor, by default model_set or a chosen related_name. The on_delete argument says what happens to related objects on deletion.

Example

author = models.ForeignKey(User, on_delete=models.CASCADE, related_name='posts')

Related concepts

The whole glossary