mirror of
https://github.com/django/django.git
synced 2025-07-24 05:36:15 +00:00
Fixed #30382 -- Allowed specifying parent classes in force_insert of Model.save().
This commit is contained in:
parent
601ffb0da3
commit
a40b0103bc
6 changed files with 138 additions and 5 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue