mirror of
https://github.com/django/django.git
synced 2025-10-25 06:36:07 +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:
committed by
Jacob Walls
parent
bee64561a6
commit
f6bd90c840
@@ -1683,15 +1683,15 @@ a join with an ``F()`` object, a ``FieldError`` will be raised:
|
|||||||
Related objects
|
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.ForeignKey`,
|
||||||
:class:`~django.db.models.OneToOneField`, or
|
:class:`~django.db.models.OneToOneField`, or
|
||||||
:class:`~django.db.models.ManyToManyField`), instances of that model will have
|
:class:`~django.db.models.ManyToManyField`), instances of the model class gain
|
||||||
a convenient API to access the related object(s).
|
accessor attributes for the related object(s).
|
||||||
|
|
||||||
Using the models at the top of this page, for example, an ``Entry`` object
|
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``
|
``e`` has its associated ``Blog`` object accessible in its ``blog`` attribute:
|
||||||
attribute: ``e.blog``.
|
``e.blog``.
|
||||||
|
|
||||||
(Behind the scenes, this functionality is implemented by Python
|
(Behind the scenes, this functionality is implemented by Python
|
||||||
:doc:`descriptors <python:howto/descriptor>`. This shouldn't really matter to
|
: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 --
|
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.
|
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
|
For example, a ``Blog`` object ``b`` has a manager that returns all related
|
||||||
``Entry`` objects via the ``entry_set`` attribute: ``b.entry_set.all()``.
|
``Entry`` objects in the ``entry_set`` attribute: ``b.entry_set.all()``.
|
||||||
|
|
||||||
All examples in this section use the sample ``Blog``, ``Author`` and ``Entry``
|
All examples in this section use the sample ``Blog``, ``Author`` and ``Entry``
|
||||||
models defined at the top of this page.
|
models defined at the top of this page.
|
||||||
|
|||||||
Reference in New Issue
Block a user