File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -367,6 +367,37 @@ Note that there are a number of :meth:`caveats to this method
367367<django.db.models.query.QuerySet.bulk_create>`, so make sure it's appropriate
368368for your use case.
369369
370+ Update in bulk
371+ --------------
372+
373+ .. versionadded:: 2.2
374+
375+ When updating objects, where possible, use the
376+ :meth:`~django.db.models.query.QuerySet.bulk_update()` method to reduce the
377+ number of SQL queries. Given a list or queryset of objects::
378+
379+ entries = Entry.objects.bulk_create([
380+ Entry(headline='This is a test'),
381+ Entry(headline='This is only a test'),
382+ ])
383+
384+ The following example::
385+
386+ entries[0].headline = 'This is not a test'
387+ entries[1].headline = 'This is no longer a test'
388+ Entry.objects.bulk_update(entries, ['headline'])
389+
390+ ...is preferable to::
391+
392+ entries[0].headline = 'This is not a test'
393+ entries.save()
394+ entries[1].headline = 'This is no longer a test'
395+ entries.save()
396+
397+ Note that there are a number of :meth:`caveats to this method
398+ <django.db.models.query.QuerySet.bulk_update>`, so make sure it's appropriate
399+ for your use case.
400+
370401Insert in bulk
371402--------------
372403
You can’t perform that action at this time.
0 commit comments