summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Graham <timograham@gmail.com>2014-08-19 06:27:27 -0400
committerTim Graham <timograham@gmail.com>2014-08-19 06:29:25 -0400
commit20e3a004ac88b127a51bb332ca2653fe06a19a97 (patch)
tree7a9576e6ffcd5e10e97c5fc6e27676c405116f93
parentc3c686b92de20b99161d1208e8aec7112213bb28 (diff)
[1.7.x] Fixed #23282 -- Corrected inheritance and reverse relations example.
Thanks knowledgepoint-devs for the report and claudep for review. Backport of 7006187064 from master
-rw-r--r--docs/topics/db/models.txt22
1 files changed, 15 insertions, 7 deletions
diff --git a/docs/topics/db/models.txt b/docs/topics/db/models.txt
index 45c4a58ecf..383d72b97e 100644
--- a/docs/topics/db/models.txt
+++ b/docs/topics/db/models.txt
@@ -1065,19 +1065,27 @@ as in the above example. However, this uses up the name that is the
default :attr:`~django.db.models.ForeignKey.related_name` value for
:class:`~django.db.models.ForeignKey` and
:class:`~django.db.models.ManyToManyField` relations. If you
-are putting those types of relations on a subclass of another model,
-you **must** specify the
-:attr:`~django.db.models.ForeignKey.related_name` attribute on each
-such field. If you forget, Django will raise an error when you run
-:djadmin:`check` or :djadmin:`migrate`.
+are putting those types of relations on a subclass of the parent model, you
+**must** specify the :attr:`~django.db.models.ForeignKey.related_name`
+attribute on each such field. If you forget, Django will raise a validation
+error.
For example, using the above ``Place`` class again, let's create another
subclass with a :class:`~django.db.models.ManyToManyField`::
class Supplier(Place):
- # Must specify related_name on all relations.
- customers = models.ManyToManyField(Restaurant, related_name='provider')
+ customers = models.ManyToManyField(Place)
+This results in the error::
+
+ Reverse query name for 'Supplier.customers' clashes with reverse query
+ name for 'Supplier.place_ptr'.
+
+ HINT: Add or change a related_name argument to the definition for
+ 'Supplier.customers' or 'Supplier.place_ptr'.
+
+Adding ``related_name`` to the ``customers`` field as follows would resolve the
+error: ``models.ManyToManyField(Place, related_name='provider')``.
Specifying the parent link field
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~