def save(self, force_insert=False, force_update=False, using=None, update_fields=None, force_update_deleted=False): if self.deleted and not force_update_deleted: raise UpdateDeletedError(_("Deleted record can not be update!")) self._soft_touch() self.modified_at = timezone.now() # set created_at and created_by in creating if self._get_pk_val is None: self.created_at = timezone.now() if self.created_by is None: self.created_by = UserUtils.get_unknown_user() return super().save(force_insert, force_update, using, update_fields)
def _soft_touch(self, by_user=None): self.modified_at = timezone.now() if by_user is not None: self.modified_by = by_user if self.modified_by is None: self.modified_by = UserUtils.get_unknown_user()
def set_user(self, user=None): if user is None: user = UserUtils.get_unknown_user() self.owner = user self.created_by = user self.modified_by = user