From 45dded8c2d1930d8e94b23aa67ce8fb47636d488 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BE=9D=E7=91=AA=E8=B2=93?= Date: Wed, 12 Aug 2020 22:41:50 +0800 Subject: [PATCH] Revised the txn_sort view so that the reorder will not pass the save() method and induce complex reorder in the accounting application. --- accounting/views.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/accounting/views.py b/accounting/views.py index e04dcb7..01f498c 100644 --- a/accounting/views.py +++ b/accounting/views.py @@ -940,9 +940,8 @@ def txn_sort(request, date): keys.sort(key=lambda x: int(post[x])) for i in range(len(keys)): post[keys[i]] = i + 1 - for txn in transactions: - txn.ord = post[F"transaction-{txn.pk}-ord"] - modified = [x for x in transactions if x.is_dirty()] + modified = [[x, post[F"transaction-{x.pk}-ord"]] for x in transactions + if x.ord != post[F"transaction-{x.pk}-ord"]] if len(modified) == 0: messages.success(request, gettext_noop( @@ -950,8 +949,8 @@ def txn_sort(request, date): return redirect(request.GET.get("r") or reverse("accounting:home")) with transaction.atomic(): - for txn in modified: - txn.save() + for x in modified: + Transaction.objects.filter(pk=x[0].pk).update(ord=x[1]) messages.success(request, gettext_noop( "The transaction orders were saved successfully.")) return redirect(request.GET.get("r") or reverse("accounting:home"))