Update the given fields in each of the given objects in the database. :param objects: List of objects to bulk create :param fields: The fields to update :param batch_size: How many objects are created in a single query :raises ValueError: If objects have no
(
self,
objects: Iterable[MODEL],
fields: Iterable[str],
batch_size: int | None = None,
)
| 915 | ) |
| 916 | |
| 917 | def bulk_update( |
| 918 | self, |
| 919 | objects: Iterable[MODEL], |
| 920 | fields: Iterable[str], |
| 921 | batch_size: int | None = None, |
| 922 | ) -> BulkUpdateQuery[MODEL]: |
| 923 | """ |
| 924 | Update the given fields in each of the given objects in the database. |
| 925 | |
| 926 | :param objects: List of objects to bulk create |
| 927 | :param fields: The fields to update |
| 928 | :param batch_size: How many objects are created in a single query |
| 929 | |
| 930 | :raises ValueError: If objects have no primary key set |
| 931 | """ |
| 932 | if any(obj.pk is None for obj in objects): |
| 933 | raise ValueError("All bulk_update() objects must have a primary key set.") |
| 934 | return BulkUpdateQuery( |
| 935 | db=self._db, |
| 936 | model=self.model, |
| 937 | q_objects=self._q_objects, |
| 938 | annotations=self._annotations, |
| 939 | custom_filters=self._custom_filters, |
| 940 | limit=self._limit, |
| 941 | orderings=self._orderings, |
| 942 | objects=objects, |
| 943 | fields=fields, |
| 944 | batch_size=batch_size, |
| 945 | ) |
| 946 | |
| 947 | def get_or_none(self, *args: Q, **kwargs: Any) -> QuerySetSingle[MODEL | None]: |
| 948 | """ |
nothing calls this directly
no test coverage detected