mirror of
https://github.com/django/django.git
synced 2025-08-03 10:34:04 +00:00
Fixed #34112 -- Added async-compatible interface to Model methods.
Thanks Adam Johnson for the review.
This commit is contained in:
parent
6103059592
commit
d5bcdf858d
6 changed files with 86 additions and 0 deletions
|
@ -132,6 +132,9 @@ value from the database::
|
|||
>>> obj.field # Loads the field from the database
|
||||
|
||||
.. method:: Model.refresh_from_db(using=None, fields=None)
|
||||
.. method:: Model.arefresh_from_db(using=None, fields=None)
|
||||
|
||||
*Asynchronous version*: ``arefresh_from_db()``
|
||||
|
||||
If you need to reload a model's values from the database, you can use the
|
||||
``refresh_from_db()`` method. When this method is called without arguments the
|
||||
|
@ -188,6 +191,10 @@ all of the instance's fields when a deferred field is reloaded::
|
|||
A helper method that returns a set containing the attribute names of all those
|
||||
fields that are currently deferred for this model.
|
||||
|
||||
.. versionchanged:: 4.2
|
||||
|
||||
``arefresh_from_db()`` method was added.
|
||||
|
||||
.. _validating-objects:
|
||||
|
||||
Validating objects
|
||||
|
@ -406,6 +413,9 @@ Saving objects
|
|||
To save an object back to the database, call ``save()``:
|
||||
|
||||
.. method:: Model.save(force_insert=False, force_update=False, using=DEFAULT_DB_ALIAS, update_fields=None)
|
||||
.. method:: Model.asave(force_insert=False, force_update=False, using=DEFAULT_DB_ALIAS, update_fields=None)
|
||||
|
||||
*Asynchronous version*: ``asave()``
|
||||
|
||||
For details on using the ``force_insert`` and ``force_update`` arguments, see
|
||||
:ref:`ref-models-force-insert`. Details about the ``update_fields`` argument
|
||||
|
@ -416,6 +426,10 @@ method. See :ref:`overriding-model-methods` for more details.
|
|||
|
||||
The model save process also has some subtleties; see the sections below.
|
||||
|
||||
.. versionchanged:: 4.2
|
||||
|
||||
``asave()`` method was added.
|
||||
|
||||
Auto-incrementing primary keys
|
||||
------------------------------
|
||||
|
||||
|
@ -644,6 +658,9 @@ Deleting objects
|
|||
================
|
||||
|
||||
.. method:: Model.delete(using=DEFAULT_DB_ALIAS, keep_parents=False)
|
||||
.. method:: Model.adelete(using=DEFAULT_DB_ALIAS, keep_parents=False)
|
||||
|
||||
*Asynchronous version*: ``adelete()``
|
||||
|
||||
Issues an SQL ``DELETE`` for the object. This only deletes the object in the
|
||||
database; the Python instance will still exist and will still have data in
|
||||
|
@ -660,6 +677,10 @@ Sometimes with :ref:`multi-table inheritance <multi-table-inheritance>` you may
|
|||
want to delete only a child model's data. Specifying ``keep_parents=True`` will
|
||||
keep the parent model's data.
|
||||
|
||||
.. versionchanged:: 4.2
|
||||
|
||||
``adelete()`` method was added.
|
||||
|
||||
Pickling objects
|
||||
================
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue