From 88e3637663ab73b6aec7ecbee5732a2aff89aa13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BE=9D=E7=91=AA=E8=B2=93?= Date: Sun, 9 Aug 2020 16:59:12 +0800 Subject: [PATCH] Revised the save() method so that it works both with the current user from the its parameter or from the parameter from the constructor. --- accounting/models.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/accounting/models.py b/accounting/models.py index 3b03e45..a84d60b 100644 --- a/accounting/models.py +++ b/accounting/models.py @@ -71,8 +71,10 @@ class Account(DirtyFieldsMixin, models.Model): else Account.objects.get(code=self.code[:-1]) if self.pk is None: self.pk = new_pk(Account) + if getattr(self, "created_by", None) is None: self.created_by = current_user - self.updated_by = current_user + if getattr(self, "updated_by", None) is None: + self.updated_by = current_user with transaction.atomic(): super(Account, self).save( force_insert=force_insert, force_update=force_update,