About Backward Relations
Django model relations have an attribute
related_name. It defines how instances of this model can be accessed from the instances of the related model. The default value is "mymodel_set".
related_name attributes are mandatory, when two models have more than one relation between each other, for example, a location can be a venue or an organizer of an event.
related_name works as a manager on the related model and as a lookup in the queries. But it's possible to customize the lookup name for queries using the
For example, the
User model has the field
groups defined as:
1 2 3 4 5 6
This means that you would access the users of the group as follows:
But you would query the users of a group this way:
Tips and Tricks Programming Django 4.x Django 3.2 Django 2.2