summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorAkash Kumar Sen <Akash-Kumar-Sen@users.noreply.github.com>2023-06-22 18:23:11 +0530
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2023-06-29 21:52:52 +0200
commita40b0103bccb8216c944188d329d8ea5eceb7e92 (patch)
treea08a0def2a0d448515f6b40409ab09e6fc129c0f /docs
parent601ffb0da3a8c3900164b356c585650c00d238b0 (diff)
Fixed #30382 -- Allowed specifying parent classes in force_insert of Model.save().
Diffstat (limited to 'docs')
-rw-r--r--docs/ref/models/instances.txt17
-rw-r--r--docs/releases/5.0.txt4
2 files changed, 21 insertions, 0 deletions
diff --git a/docs/ref/models/instances.txt b/docs/ref/models/instances.txt
index 346ae55130..6bfd521aaa 100644
--- a/docs/ref/models/instances.txt
+++ b/docs/ref/models/instances.txt
@@ -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
diff --git a/docs/releases/5.0.txt b/docs/releases/5.0.txt
index 60de6f81e7..f5f4ecd668 100644
--- a/docs/releases/5.0.txt
+++ b/docs/releases/5.0.txt
@@ -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
~~~~~~~~~~