Fixed #30106 -- Made order_with_respect_to updates use QuerySet.bulk_update().
This commit is contained in:
parent
2110b17924
commit
8d2dcc47cd
|
@ -1782,11 +1782,9 @@ def method_set_order(self, ordered_obj, id_list, using=None):
|
||||||
using = DEFAULT_DB_ALIAS
|
using = DEFAULT_DB_ALIAS
|
||||||
order_wrt = ordered_obj._meta.order_with_respect_to
|
order_wrt = ordered_obj._meta.order_with_respect_to
|
||||||
filter_args = order_wrt.get_forward_related_filter(self)
|
filter_args = order_wrt.get_forward_related_filter(self)
|
||||||
# FIXME: It would be nice if there was an "update many" version of update
|
ordered_obj.objects.db_manager(using).filter(**filter_args).bulk_update([
|
||||||
# for situations like this.
|
ordered_obj(pk=pk, _order=order) for order, pk in enumerate(id_list)
|
||||||
with transaction.atomic(using=using, savepoint=False):
|
], ['_order'])
|
||||||
for i, j in enumerate(id_list):
|
|
||||||
ordered_obj.objects.filter(pk=j, **filter_args).update(_order=i)
|
|
||||||
|
|
||||||
|
|
||||||
def method_get_order(self, ordered_obj):
|
def method_get_order(self, ordered_obj):
|
||||||
|
|
Loading…
Reference in New Issue