Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Docs for related_query_name

  • Loading branch information...
commit 12cb0df10f12e715bcaafbee4290c92d4ed6f111 1 parent b21e96d
Andrew Godwin authored

Showing 1 changed file with 22 additions and 0 deletions. Show diff stats Hide diff stats

  1. 22  docs/ref/models/fields.txt
22  docs/ref/models/fields.txt
@@ -1083,6 +1083,22 @@ define the details of how the relation works.
1083 1083
 
1084 1084
         user = models.ForeignKey(User, related_name='+')
1085 1085
 
  1086
+.. attribute:: ForeignKey.related_query_name
  1087
+
  1088
+    .. versionadded:: 1.6
  1089
+
  1090
+    The name to use for the reverse filter name from the target model.
  1091
+    Defaults to the value of :attr:`related_name` if it is set, otherwise it
  1092
+    defaults to the name of the model::
  1093
+
  1094
+        # Declare the ForeignKey with related_query_name
  1095
+        class Tag(models.Model):
  1096
+            article = models.ForeignKey(Article, related_name="tags", related_query_name="tag")
  1097
+            name = models.CharField(max_length=255)
  1098
+
  1099
+        # That's now the name of the reverse filter
  1100
+        article_instance.filter(tag__name="important")
  1101
+
1086 1102
 .. attribute:: ForeignKey.to_field
1087 1103
 
1088 1104
     The field on the related object that the relation is to. By default, Django
@@ -1207,6 +1223,12 @@ that control how the relationship functions.
1207 1223
         users = models.ManyToManyField(User, related_name='u+')
1208 1224
         referents = models.ManyToManyField(User, related_name='ref+')
1209 1225
 
  1226
+.. attribute:: ForeignKey.related_query_name
  1227
+
  1228
+    .. versionadded:: 1.6
  1229
+
  1230
+    Same as :attr:`ForeignKey.related_query_name`.
  1231
+
1210 1232
 .. attribute:: ManyToManyField.limit_choices_to
1211 1233
 
1212 1234
     Same as :attr:`ForeignKey.limit_choices_to`.

0 notes on commit 12cb0df

rosnfeld

Apologies if I have this wrong as I am new to Django, but this is a typo, right? (should be ManyToManyField.related_query_name ?)

Andrew Godwin

You're right; I'll patch it. Thanks!

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