mirror of
https://github.com/django/django.git
synced 2024-12-22 17:16:24 +00:00
Fixed #28514 -- Clarifed docs about idempotence of RelatedManager.add().
This commit is contained in:
parent
1834490a0c
commit
abe6c5defe
1
AUTHORS
1
AUTHORS
@ -385,6 +385,7 @@ answer newbie questions, and generally made Django that much better:
|
|||||||
Jeremy Dunck <jdunck@gmail.com>
|
Jeremy Dunck <jdunck@gmail.com>
|
||||||
Jeremy Lainé <jeremy.laine@m4x.org>
|
Jeremy Lainé <jeremy.laine@m4x.org>
|
||||||
Jesse Young <adunar@gmail.com>
|
Jesse Young <adunar@gmail.com>
|
||||||
|
Jezeniel Zapanta <jezeniel.zapanta@gmail.com>
|
||||||
jhenry <jhenry@theonion.com>
|
jhenry <jhenry@theonion.com>
|
||||||
Jim Dalton <jim.dalton@gmail.com>
|
Jim Dalton <jim.dalton@gmail.com>
|
||||||
Jimmy Song <jaejoon@gmail.com>
|
Jimmy Song <jaejoon@gmail.com>
|
||||||
|
@ -56,11 +56,15 @@ Related objects reference
|
|||||||
manager perform the update by calling ``e.save()``.
|
manager perform the update by calling ``e.save()``.
|
||||||
|
|
||||||
Using ``add()`` with a many-to-many relationship, however, will not
|
Using ``add()`` with a many-to-many relationship, however, will not
|
||||||
call any ``save()`` methods, but rather create the relationships
|
call any ``save()`` methods (the ``bulk`` argument doesn't exist), but
|
||||||
using :meth:`QuerySet.bulk_create()
|
rather create the relationships using :meth:`QuerySet.bulk_create()
|
||||||
<django.db.models.query.QuerySet.bulk_create>`. If you need to execute
|
<django.db.models.query.QuerySet.bulk_create>`. If you need to execute
|
||||||
some custom logic when a relationship is created, listen to the
|
some custom logic when a relationship is created, listen to the
|
||||||
:data:`~django.db.models.signals.m2m_changed` signal.
|
:data:`~django.db.models.signals.m2m_changed` signal, which will
|
||||||
|
trigger ``pre_add`` and ``post_add`` actions.
|
||||||
|
|
||||||
|
Using ``add()`` on a relation that already exists won't duplicate the
|
||||||
|
relation, but it will still trigger signals.
|
||||||
|
|
||||||
.. method:: create(**kwargs)
|
.. method:: create(**kwargs)
|
||||||
|
|
||||||
|
@ -75,7 +75,7 @@ Create another ``Article``, and set it to appear in both ``Publications``::
|
|||||||
>>> a2.publications.add(p1, p2)
|
>>> a2.publications.add(p1, p2)
|
||||||
>>> a2.publications.add(p3)
|
>>> a2.publications.add(p3)
|
||||||
|
|
||||||
Adding a second time is OK::
|
Adding a second time is OK, it will not duplicate the relation::
|
||||||
|
|
||||||
>>> a2.publications.add(p3)
|
>>> a2.publications.add(p3)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user