From a40b0103bccb8216c944188d329d8ea5eceb7e92 Mon Sep 17 00:00:00 2001 From: Akash Kumar Sen Date: Thu, 22 Jun 2023 18:23:11 +0530 Subject: Fixed #30382 -- Allowed specifying parent classes in force_insert of Model.save(). --- docs/ref/models/instances.txt | 17 +++++++++++++++++ docs/releases/5.0.txt | 4 ++++ 2 files changed, 21 insertions(+) (limited to 'docs') 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 `, 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 ` directly instead of requiring expansion with the ``choices`` attribute. +* The :ref:`force_insert ` argument of + :meth:`.Model.save` now allows specifying a tuple of parent classes that must + be forced to be inserted. + Pagination ~~~~~~~~~~ -- cgit v1.3