1
0
mirror of https://github.com/django/django.git synced 2025-10-24 14:16:09 +00:00

Refs #28586 -- Edited related objects documentation.

This change aims to make this section clearer and ready to add a description of
fetch modes.
This commit is contained in:
Adam Johnson
2025-02-20 21:57:36 +00:00
committed by Jacob Walls
parent bee64561a6
commit f6bd90c840

View File

@@ -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 <python:howto/descriptor>`. 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.