Fixed #34135 -- Added async-compatible interface to related managers.

This commit is contained in:
Jon Janzen 2022-11-03 19:57:33 +01:00 committed by Mariusz Felisiak
parent 41e8931c2c
commit 321ecb40f4
7 changed files with 188 additions and 8 deletions

View file

@ -37,6 +37,9 @@ Related objects reference
``topping.pizza_set`` and on ``pizza.toppings``.
.. method:: add(*objs, bulk=True, through_defaults=None)
.. method:: aadd(*objs, bulk=True, through_defaults=None)
*Asynchronous version*: ``aadd``
Adds the specified model objects to the related object set.
@ -75,6 +78,10 @@ Related objects reference
dictionary and they will be evaluated once before creating any
intermediate instance(s).
.. versionchanged:: 4.2
``aadd()`` method was added.
.. method:: create(through_defaults=None, **kwargs)
.. method:: acreate(through_defaults=None, **kwargs)
@ -118,6 +125,9 @@ Related objects reference
``acreate()`` method was added.
.. method:: remove(*objs, bulk=True)
.. method:: aremove(*objs, bulk=True)
*Asynchronous version*: ``aremove``
Removes the specified model objects from the related object set::
@ -157,7 +167,14 @@ Related objects reference
For many-to-many relationships, the ``bulk`` keyword argument doesn't
exist.
.. versionchanged:: 4.2
``aremove()`` method was added.
.. method:: clear(bulk=True)
.. method:: aclear(bulk=True)
*Asynchronous version*: ``aclear``
Removes all objects from the related object set::
@ -174,7 +191,14 @@ Related objects reference
For many-to-many relationships, the ``bulk`` keyword argument doesn't
exist.
.. versionchanged:: 4.2
``aclear()`` method was added.
.. method:: set(objs, bulk=True, clear=False, through_defaults=None)
.. method:: aset(objs, bulk=True, clear=False, through_defaults=None)
*Asynchronous version*: ``aset``
Replace the set of related objects::
@ -207,13 +231,19 @@ Related objects reference
dictionary and they will be evaluated once before creating any
intermediate instance(s).
.. versionchanged:: 4.2
``aset()`` method was added.
.. note::
Note that ``add()``, ``create()``, ``remove()``, ``clear()``, and
``set()`` all apply database changes immediately for all types of
related fields. In other words, there is no need to call ``save()``
on either end of the relationship.
Note that ``add()``, ``aadd()``, ``create()``, ``acreate()``,
``remove()``, ``aremove()``, ``clear()``, ``aclear()``, ``set()``, and
``aset()`` all apply database changes immediately for all types of
related fields. In other words, there is no need to call
``save()``/``asave()`` on either end of the relationship.
If you use :meth:`~django.db.models.query.QuerySet.prefetch_related`,
the ``add()``, ``remove()``, ``clear()``, and ``set()`` methods clear
the prefetched cache.
the ``add()``, ``aadd()``, ``remove()``, ``aremove()``, ``clear()``,
``aclear()``, ``set()``, and ``aset()`` methods clear the prefetched
cache.