Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #10913 -- Documented how related_name affects QuerySet filtering

Thanks neithere for the suggestion.
  • Loading branch information...
commit 75bb6ba96660e2a06e18d99120c05db2bb9fa9cc 1 parent e1b7723
Tim Graham authored October 02, 2013
9  docs/ref/models/fields.txt
@@ -1078,10 +1078,11 @@ define the details of how the relation works.
1078 1078
 .. attribute:: ForeignKey.related_name
1079 1079
 
1080 1080
     The name to use for the relation from the related object back to this one.
1081  
-    See the :ref:`related objects documentation <backwards-related-objects>` for
1082  
-    a full explanation and example. Note that you must set this value
1083  
-    when defining relations on :ref:`abstract models
1084  
-    <abstract-base-classes>`; and when you do so
  1081
+    It's also the default value for :attr:`related_query_name` (the name to use
  1082
+    for the reverse filter name from the target model). See the :ref:`related
  1083
+    objects documentation <backwards-related-objects>` for a full explanation
  1084
+    and example. Note that you must set this value when defining relations on
  1085
+    :ref:`abstract models <abstract-base-classes>`; and when you do so
1085 1086
     :ref:`some special syntax <abstract-related-name>` is available.
1086 1087
 
1087 1088
     If you'd prefer Django not to create a backwards relation, set
14  docs/topics/db/queries.txt
@@ -1124,8 +1124,9 @@ Example::
1124 1124
     >>> b.entry_set.filter(headline__contains='Lennon')
1125 1125
     >>> b.entry_set.count()
1126 1126
 
1127  
-You can override the ``FOO_set`` name by setting the ``related_name``
1128  
-parameter in the ``ForeignKey()`` definition. For example, if the ``Entry``
  1127
+You can override the ``FOO_set`` name by setting the
  1128
+:attr:`~django.db.models.ForeignKey.related_name` parameter in the
  1129
+:class:`~django.db.models.ForeignKey` definition. For example, if the ``Entry``
1129 1130
 model was altered to ``blog = ForeignKey(Blog, related_name='entries')``, the
1130 1131
 above example code would look like this::
1131 1132
 
@@ -1224,10 +1225,11 @@ An example makes this easier to understand::
1224 1225
     a.entry_set.all() # Returns all Entry objects for this Author.
1225 1226
 
1226 1227
 Like :class:`~django.db.models.ForeignKey`,
1227  
-:class:`~django.db.models.ManyToManyField` can specify ``related_name``. In the
1228  
-above example, if the :class:`~django.db.models.ManyToManyField` in ``Entry``
1229  
-had specified ``related_name='entries'``, then each ``Author`` instance would
1230  
-have an ``entries`` attribute instead of ``entry_set``.
  1228
+:class:`~django.db.models.ManyToManyField` can specify
  1229
+:attr:`~django.db.models.ManyToManyField.related_name`. In the above example,
  1230
+if the :class:`~django.db.models.ManyToManyField` in ``Entry`` had specified
  1231
+``related_name='entries'``, then each ``Author`` instance would have an
  1232
+``entries`` attribute instead of ``entry_set``.
1231 1233
 
1232 1234
 One-to-one relationships
1233 1235
 ------------------------

0 notes on commit 75bb6ba

Please sign in to comment.
Something went wrong with that request. Please try again.