mirror of
https://github.com/django/django.git
synced 2025-11-07 07:15:35 +00:00
Fixed #6707 -- Added RelatedManager.set() and made descriptors' __set__ use it.
Thanks Anssi Kääriäinen, Carl Meyer, Collin Anderson, and Tim Graham for the reviews.
This commit is contained in:
@@ -127,7 +127,10 @@ Management Commands
|
||||
Models
|
||||
^^^^^^
|
||||
|
||||
* ...
|
||||
* Added the :meth:`RelatedManager.set()
|
||||
<django.db.models.fields.related.RelatedManager.set()>` method to the related
|
||||
managers created by ``ForeignKey``, ``GenericForeignKey``, and
|
||||
``ManyToManyField``.
|
||||
|
||||
Signals
|
||||
^^^^^^^
|
||||
@@ -192,6 +195,25 @@ used by the egg loader to detect if setuptools was installed. The ``is_usable``
|
||||
attribute is now removed and the egg loader instead fails at runtime if
|
||||
setuptools is not installed.
|
||||
|
||||
Related set direct assignment
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
:ref:`Direct assignment <direct-assignment>`) used to perform a ``clear()``
|
||||
followed by a call to ``add()``. This caused needlessly large data changes
|
||||
and prevented using the :data:`~django.db.models.signals.m2m_changed` signal
|
||||
to track individual changes in many-to-many relations.
|
||||
|
||||
Direct assignment now relies on the the new
|
||||
:meth:`django.db.models.fields.related.RelatedManager.set()` method on
|
||||
related managers which by default only processes changes between the
|
||||
existing related set and the one that's newly assigned. The previous behavior
|
||||
can be restored by replacing direct assignment by a call to ``set()`` with
|
||||
the keyword argument ``clear=True``.
|
||||
|
||||
``ModelForm``, and therefore ``ModelAdmin``, internally rely on direct
|
||||
assignment for many-to-many relations and as a consequence now use the new
|
||||
behavior.
|
||||
|
||||
Miscellaneous
|
||||
~~~~~~~~~~~~~
|
||||
|
||||
|
||||
Reference in New Issue
Block a user