Update the given fields in each of the given objects in the database. This method efficiently updates the given fields on the provided model instances, generally with one query. .. code-block:: python3 users = [ await User.create(name="...", ema
(
cls: type[MODEL],
objects: Iterable[MODEL],
fields: Iterable[str],
batch_size: int | None = None,
using_db: BaseDBAsyncClient | None = None,
)
| 1389 | |
| 1390 | @classmethod |
| 1391 | def bulk_update( |
| 1392 | cls: type[MODEL], |
| 1393 | objects: Iterable[MODEL], |
| 1394 | fields: Iterable[str], |
| 1395 | batch_size: int | None = None, |
| 1396 | using_db: BaseDBAsyncClient | None = None, |
| 1397 | ) -> BulkUpdateQuery[MODEL]: |
| 1398 | """ |
| 1399 | Update the given fields in each of the given objects in the database. |
| 1400 | This method efficiently updates the given fields on the provided model instances, generally with one query. |
| 1401 | |
| 1402 | .. code-block:: python3 |
| 1403 | |
| 1404 | users = [ |
| 1405 | await User.create(name="...", email="..."), |
| 1406 | await User.create(name="...", email="...") |
| 1407 | ] |
| 1408 | users[0].name = 'name1' |
| 1409 | users[1].name = 'name2' |
| 1410 | |
| 1411 | await User.bulk_update(users, fields=['name']) |
| 1412 | |
| 1413 | :param objects: List of objects to bulk create |
| 1414 | :param fields: The fields to update |
| 1415 | :param batch_size: How many objects are created in a single query |
| 1416 | :param using_db: Specific DB connection to use instead of default bound |
| 1417 | """ |
| 1418 | return cls._db_queryset(using_db, for_write=True).bulk_update(objects, fields, batch_size) |
| 1419 | |
| 1420 | @classmethod |
| 1421 | async def in_bulk( |