From 354c1524b38c9b9f052c1d78dcbfa6ed5559aeb3 Mon Sep 17 00:00:00 2001 From: Craig Smith Date: Tue, 20 Oct 2020 16:36:03 +1100 Subject: [PATCH] Fixed #32045 -- Doc'd GenericRelatedObjectManager methods. This also documents that .remove() and clear() methods delete related objects. --- docs/ref/contrib/contenttypes.txt | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/docs/ref/contrib/contenttypes.txt b/docs/ref/contrib/contenttypes.txt index 28a2e40819..7550f4fc8d 100644 --- a/docs/ref/contrib/contenttypes.txt +++ b/docs/ref/contrib/contenttypes.txt @@ -391,6 +391,36 @@ be used to retrieve their associated ``TaggedItems``:: >>> b.tags.all() , ]> +You can also use ``add()``, ``create()``, or ``set()`` to create +relationships:: + + >>> t3 = TaggedItem(tag='Web development') + >>> b.tags.add(t3, bulk=False) + >>> b.tags.create(tag='Web framework') + + >>> b.tags.all() + , , , ]> + >>> b.tags.set([t1, t3]) + >>> b.tags.all() + , ]> + +The ``remove()`` call will bulk delete the specified model objects:: + + >>> b.tags.remove(t3) + >>> b.tags.all() + ]> + >>> TaggedItem.objects.all() + ]> + +The ``clear()`` method can be used to bulk delete all related objects for an +instance:: + + >>> b.tags.clear() + >>> b.tags.all() + + >>> TaggedItem.objects.all() + + Defining :class:`~django.contrib.contenttypes.fields.GenericRelation` with ``related_query_name`` set allows querying from the related object::