summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorTim Graham <timograham@gmail.com>2013-10-02 12:12:53 -0400
committerTim Graham <timograham@gmail.com>2013-10-02 12:13:44 -0400
commit06b149e220f98cd643a4445db1b5719daac0d56f (patch)
tree9b356a657abc47117bf82f43987cf26c4952bac3 /docs
parent9b89fcc0b0c85dad5034b048e436f06a981f28e8 (diff)
[1.6.x] Fixed #10913 -- Documented how related_name affects QuerySet filtering
Thanks neithere for the suggestion. Backport of 75bb6ba966 from master
Diffstat (limited to 'docs')
-rw-r--r--docs/ref/models/fields.txt9
-rw-r--r--docs/topics/db/queries.txt14
2 files changed, 13 insertions, 10 deletions
diff --git a/docs/ref/models/fields.txt b/docs/ref/models/fields.txt
index 2005e4a95c..a8f1eaa917 100644
--- a/docs/ref/models/fields.txt
+++ b/docs/ref/models/fields.txt
@@ -1075,10 +1075,11 @@ define the details of how the relation works.
.. attribute:: ForeignKey.related_name
The name to use for the relation from the related object back to this one.
- See the :ref:`related objects documentation <backwards-related-objects>` for
- a full explanation and example. Note that you must set this value
- when defining relations on :ref:`abstract models
- <abstract-base-classes>`; and when you do so
+ It's also the default value for :attr:`related_query_name` (the name to use
+ for the reverse filter name from the target model). See the :ref:`related
+ objects documentation <backwards-related-objects>` for a full explanation
+ and example. Note that you must set this value when defining relations on
+ :ref:`abstract models <abstract-base-classes>`; and when you do so
:ref:`some special syntax <abstract-related-name>` is available.
If you'd prefer Django not to create a backwards relation, set
diff --git a/docs/topics/db/queries.txt b/docs/topics/db/queries.txt
index 4aa9429c73..805a72d3f5 100644
--- a/docs/topics/db/queries.txt
+++ b/docs/topics/db/queries.txt
@@ -1143,8 +1143,9 @@ Example::
>>> b.entry_set.filter(headline__contains='Lennon')
>>> b.entry_set.count()
-You can override the ``FOO_set`` name by setting the ``related_name``
-parameter in the ``ForeignKey()`` definition. For example, if the ``Entry``
+You can override the ``FOO_set`` name by setting the
+:attr:`~django.db.models.ForeignKey.related_name` parameter in the
+:class:`~django.db.models.ForeignKey` definition. For example, if the ``Entry``
model was altered to ``blog = ForeignKey(Blog, related_name='entries')``, the
above example code would look like this::
@@ -1218,10 +1219,11 @@ An example makes this easier to understand::
a.entry_set.all() # Returns all Entry objects for this Author.
Like :class:`~django.db.models.ForeignKey`,
-:class:`~django.db.models.ManyToManyField` can specify ``related_name``. In the
-above example, if the :class:`~django.db.models.ManyToManyField` in ``Entry``
-had specified ``related_name='entries'``, then each ``Author`` instance would
-have an ``entries`` attribute instead of ``entry_set``.
+:class:`~django.db.models.ManyToManyField` can specify
+:attr:`~django.db.models.ManyToManyField.related_name`. In the above example,
+if the :class:`~django.db.models.ManyToManyField` in ``Entry`` had specified
+``related_name='entries'``, then each ``Author`` instance would have an
+``entries`` attribute instead of ``entry_set``.
One-to-one relationships
------------------------