From f6bd90c84050a1c74fe2161cced00e7282cb845c Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Thu, 20 Feb 2025 21:57:36 +0000 Subject: [PATCH] Refs #28586 -- Edited related objects documentation. This change aims to make this section clearer and ready to add a description of fetch modes. --- docs/topics/db/queries.txt | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/docs/topics/db/queries.txt b/docs/topics/db/queries.txt index 3451f71fba..d24505b039 100644 --- a/docs/topics/db/queries.txt +++ b/docs/topics/db/queries.txt @@ -1683,15 +1683,15 @@ a join with an ``F()`` object, a ``FieldError`` will be raised: Related objects =============== -When you define a relationship in a model (i.e., a +When you define a relationship in a model (with :class:`~django.db.models.ForeignKey`, :class:`~django.db.models.OneToOneField`, or -:class:`~django.db.models.ManyToManyField`), instances of that model will have -a convenient API to access the related object(s). +:class:`~django.db.models.ManyToManyField`), instances of the model class gain +accessor attributes for the related object(s). Using the models at the top of this page, for example, an ``Entry`` object -``e`` can get its associated ``Blog`` object by accessing the ``blog`` -attribute: ``e.blog``. +``e`` has its associated ``Blog`` object accessible in its ``blog`` attribute: +``e.blog``. (Behind the scenes, this functionality is implemented by Python :doc:`descriptors `. This shouldn't really matter to @@ -1699,8 +1699,8 @@ you, but we point it out here for the curious.) Django also creates API accessors for the "other" side of the relationship -- the link from the related model to the model that defines the relationship. -For example, a ``Blog`` object ``b`` has access to a list of all related -``Entry`` objects via the ``entry_set`` attribute: ``b.entry_set.all()``. +For example, a ``Blog`` object ``b`` has a manager that returns all related +``Entry`` objects in the ``entry_set`` attribute: ``b.entry_set.all()``. All examples in this section use the sample ``Blog``, ``Author`` and ``Entry`` models defined at the top of this page.