Fixed #31282 -- Corrected RelatedManager docs for using add/remove/set with PKs.

This commit is contained in:
Carlton Gibson 2020-02-18 10:48:19 +01:00 committed by Carlton Gibson
parent 2a038521c4
commit 3bbf9a489a
1 changed files with 8 additions and 8 deletions

View File

@ -66,8 +66,8 @@ Related objects reference
Using ``add()`` on a relation that already exists won't duplicate the Using ``add()`` on a relation that already exists won't duplicate the
relation, but it will still trigger signals. relation, but it will still trigger signals.
``add()`` also accepts the field the relation points to as an argument. For many-to-many relationships ``add()`` accepts either model instances
The above example can be rewritten as ``b.entry_set.add(234)``. or field values, normally primary keys, as the ``*objs`` argument.
Use the ``through_defaults`` argument to specify values for the new Use the ``through_defaults`` argument to specify values for the new
:ref:`intermediate model <intermediary-manytomany>` instance(s), if :ref:`intermediate model <intermediary-manytomany>` instance(s), if
@ -134,9 +134,9 @@ Related objects reference
:data:`~django.db.models.signals.m2m_changed` signal if you wish to :data:`~django.db.models.signals.m2m_changed` signal if you wish to
execute custom code when a relationship is deleted. execute custom code when a relationship is deleted.
Similarly to :meth:`add()`, ``remove()`` also accepts the field the For many-to-many relationships ``remove()`` accepts either model
relation points to as an argument. The above example can be rewritten instances or field values, normally primary keys, as the ``*objs``
as ``b.entry_set.remove(234)``. argument.
For :class:`~django.db.models.ForeignKey` objects, this method only For :class:`~django.db.models.ForeignKey` objects, this method only
exists if ``null=True``. If the related field can't be set to ``None`` exists if ``null=True``. If the related field can't be set to ``None``
@ -198,9 +198,9 @@ Related objects reference
race conditions. For instance, new objects may be added to the database race conditions. For instance, new objects may be added to the database
in between the call to ``clear()`` and the call to ``add()``. in between the call to ``clear()`` and the call to ``add()``.
Similarly to :meth:`add()`, ``set()`` also accepts the field the For many-to-many relationships ``set()`` accepts a list of either model
relation points to as an argument. The above example can be rewritten instances or field values, normally primary keys, as the ``objs``
as ``e.related_set.set([obj1.pk, obj2.pk, obj3.pk])``. argument.
Use the ``through_defaults`` argument to specify values for the new Use the ``through_defaults`` argument to specify values for the new
:ref:`intermediate model <intermediary-manytomany>` instance(s), if :ref:`intermediate model <intermediary-manytomany>` instance(s), if