Revised the save() method so that it works both with the current user from the its parameter or from the parameter from the constructor.

This commit is contained in:
依瑪貓 2020-08-09 16:59:12 +08:00
parent bbd3d0e470
commit 88e3637663

View File

@ -71,7 +71,9 @@ 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
if getattr(self, "updated_by", None) is None:
self.updated_by = current_user
with transaction.atomic():
super(Account, self).save(