From 8d2dcc47cd7f6069a1fa2c5b67a329cec5846b7e Mon Sep 17 00:00:00 2001 From: Simon Charette Date: Wed, 16 Jan 2019 21:56:06 -0600 Subject: [PATCH] Fixed #30106 -- Made order_with_respect_to updates use QuerySet.bulk_update(). --- django/db/models/base.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/django/db/models/base.py b/django/db/models/base.py index faed79cc2f..b53b33e47e 100644 --- a/django/db/models/base.py +++ b/django/db/models/base.py @@ -1782,11 +1782,9 @@ def method_set_order(self, ordered_obj, id_list, using=None): using = DEFAULT_DB_ALIAS order_wrt = ordered_obj._meta.order_with_respect_to filter_args = order_wrt.get_forward_related_filter(self) - # FIXME: It would be nice if there was an "update many" version of update - # for situations like this. - with transaction.atomic(using=using, savepoint=False): - for i, j in enumerate(id_list): - ordered_obj.objects.filter(pk=j, **filter_args).update(_order=i) + ordered_obj.objects.db_manager(using).filter(**filter_args).bulk_update([ + ordered_obj(pk=pk, _order=order) for order, pk in enumerate(id_list) + ], ['_order']) def method_get_order(self, ordered_obj):