From 785087fc8caf8abddf758663e1b94159ed20768a 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:28 +0800 Subject: [PATCH] Revised the delete method of the transaction data model so that the reorder will not pass the save() method and induce complex reorder in the accounting application. --- accounting/models.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/accounting/models.py b/accounting/models.py index 11d2b52..694dba4 100644 --- a/accounting/models.py +++ b/accounting/models.py @@ -245,15 +245,14 @@ class Transaction(DirtyFieldsMixin, models.Model): .order_by("ord")) txn_to_sort = [] for i in range(len(txn_same_day)): - txn_same_day[i].ord = i + 1 - if txn_same_day[i].is_dirty(): - txn_to_sort.append(txn_same_day[i]) + if txn_same_day[i].ord != i + 1: + txn_to_sort.append([txn_same_day[i], i + 1]) with transaction.atomic(): for record in self.record_set.all(): record.delete() super().delete(using=using, keep_parents=keep_parents) - for txn in txn_to_sort: - txn.save() + for x in txn_to_sort: + Transaction.objects.filter(pk=x[0].pk).update(ord=x[1]) class Meta: db_table = "accounting_transactions"