mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +00:00
Fixed #30382 -- Allowed specifying parent classes in force_insert of Model.save().
This commit is contained in:
committed by
Mariusz Felisiak
parent
601ffb0da3
commit
a40b0103bc
@@ -589,6 +589,18 @@ row. In these cases you can pass the ``force_insert=True`` or
|
||||
Passing both parameters is an error: you cannot both insert *and* update at the
|
||||
same time!
|
||||
|
||||
When using :ref:`multi-table inheritance <multi-table-inheritance>`, it's also
|
||||
possible to provide a tuple of parent classes to ``force_insert`` in order to
|
||||
force ``INSERT`` statements for each base. For example::
|
||||
|
||||
Restaurant(pk=1, name="Bob's Cafe").save(force_insert=(Place,))
|
||||
|
||||
Restaurant(pk=1, name="Bob's Cafe", rating=4).save(force_insert=(Place, Rating))
|
||||
|
||||
You can pass ``force_insert=(models.Model,)`` to force an ``INSERT`` statement
|
||||
for all parents. By default, ``force_insert=True`` only forces the insertion of
|
||||
a new row for the current model.
|
||||
|
||||
It should be very rare that you'll need to use these parameters. Django will
|
||||
almost always do the right thing and trying to override that will lead to
|
||||
errors that are difficult to track down. This feature is for advanced use
|
||||
@@ -596,6 +608,11 @@ only.
|
||||
|
||||
Using ``update_fields`` will force an update similarly to ``force_update``.
|
||||
|
||||
.. versionchanged:: 5.0
|
||||
|
||||
Support for passing a tuple of parent classes to ``force_insert`` was
|
||||
added.
|
||||
|
||||
.. _ref-models-field-updates-using-f-expressions:
|
||||
|
||||
Updating attributes based on existing fields
|
||||
|
||||
@@ -335,6 +335,10 @@ Models
|
||||
:ref:`Choices classes <field-choices-enum-types>` directly instead of
|
||||
requiring expansion with the ``choices`` attribute.
|
||||
|
||||
* The :ref:`force_insert <ref-models-force-insert>` argument of
|
||||
:meth:`.Model.save` now allows specifying a tuple of parent classes that must
|
||||
be forced to be inserted.
|
||||
|
||||
Pagination
|
||||
~~~~~~~~~~
|
||||
|
||||
|
||||
Reference in New Issue
Block a user