From e7fa8aff432a90b6df9914d63aad239164b6b4d4 Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Fri, 10 Jul 2020 14:27:31 +0100 Subject: [PATCH] Improved ManyToManyField.through docs. --- docs/ref/models/fields.txt | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/docs/ref/models/fields.txt b/docs/ref/models/fields.txt index a72c9b38626..4e3cd108b9e 100644 --- a/docs/ref/models/fields.txt +++ b/docs/ref/models/fields.txt @@ -1818,6 +1818,13 @@ that control how the relationship functions. :ref:`extra data with a many-to-many relationship `. + .. note:: + + If you don't want multiple associations between the same instances, add + a :class:`~django.db.models.UniqueConstraint` including the from and to + fields. Django's automatically generated many-to-many tables include + such a constraint. + .. note:: Recursive relationships using an intermediary model and defined as @@ -1851,7 +1858,9 @@ that control how the relationship functions. points (i.e. the target model instance). This class can be used to query associated records for a given model - instance like a normal model. + instance like a normal model:: + + Model.m2mfield.through.objects.all() .. attribute:: ManyToManyField.through_fields