diff options
| author | Tobias Kunze <r@rixx.de> | 2019-04-17 13:37:56 +0200 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2019-05-07 12:58:55 +0200 |
| commit | 769f87fd2426aa7b21d535892fce75f070c21238 (patch) | |
| tree | 2b5d41f087a63be43626bf4262e2b8471f429c1b /docs/ref | |
| parent | bf9e0e342da3ed2f74ee0ec34e75bdcbedde40a9 (diff) | |
[2.2.x] Fixed #26678 -- Doc'd that RelatedManager.add()/remove()/set() accepts the field the relation points to.
Backport of a44a21a22f20c1a710670676fcca798dd6bb5ac0 from master
Diffstat (limited to 'docs/ref')
| -rw-r--r-- | docs/ref/models/relations.txt | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/docs/ref/models/relations.txt b/docs/ref/models/relations.txt index 6274506a87..ac61164d54 100644 --- a/docs/ref/models/relations.txt +++ b/docs/ref/models/relations.txt @@ -66,6 +66,9 @@ Related objects reference Using ``add()`` on a relation that already exists won't duplicate the relation, but it will still trigger signals. + ``add()`` also accepts the field the relation points to as an argument. + The above example can be rewritten as ``b.entry_set.add(234)``. + Use the ``through_defaults`` argument to specify values for the new :ref:`intermediate model <intermediary-manytomany>` instance(s), if needed. @@ -128,6 +131,10 @@ Related objects reference :data:`~django.db.models.signals.m2m_changed` signal if you wish to execute custom code when a relationship is deleted. + Similarly to :meth:`add()`, ``remove()`` also accepts the field the + relation points to as an argument. The above example can be rewritten + as ``b.entry_set.remove(234)``. + For :class:`~django.db.models.ForeignKey` objects, this method only exists if ``null=True``. If the related field can't be set to ``None`` (``NULL``), then an object can't be removed from a relation without @@ -188,6 +195,10 @@ Related objects reference race conditions. For instance, new objects may be added to the database in between the call to ``clear()`` and the call to ``add()``. + Similarly to :meth:`add()`, ``set()`` also accepts the field the + relation points to as an argument. The above example can be rewritten + as ``e.related_set.set([obj1.pk, obj2.pk, obj3.pk])``. + Use the ``through_defaults`` argument to specify values for the new :ref:`intermediate model <intermediary-manytomany>` instance(s), if needed. |
