What is the related_name attribute on a relationship field, and how does it affect reverse lookups?
Last updated
related_namesets the reverse accessor from the target model back to the model defining the FK/M2M, replacing the default<model>_set(e.g.author.booksinstead ofauthor.book_set).Distinct names resolve clashes when two FKs point to the same model. Setting
related_name="+"disables the reverse relation.The name is also used in reverse query filters like
books__title, unless overridden byrelated_query_name.
- https://www.geeksforgeeks.org/python/crud-operation-on-a-django-model-with-a-many-to-many-field/
- https://www.geeksforgeeks.org/python/how-to-express-a-one-to-many-relationship-in-django/
- https://www.geeksforgeeks.org/python/include-related-model-fields-in-django-rest-framework/
- https://www.geeksforgeeks.org/python/the-most-efficient-way-to-store-a-list-in-django-models/
- https://www.geeksforgeeks.org/python/quiz-application-using-django/
- https://www.geeksforgeeks.org/python/best-practices-for-professional-developer-django-framework/
- https://dev.to/guzmanojero/understanding-relatedname-in-django-with-clear-examples-2em5