我想在删除后将数据保留在我的数据库中并进行跟踪。我怎样才能实现这个目标?

I want to keep data in my database after deletion and track it. How can I achive this goal?

我有一个简单的模型类别。我想软删除实例并在我的数据库中跟踪它们

from django.db import models
from django.contrib.auth.models import User
from django.utils import timezone
from django_currentuser.middleware import get_current_user, get_current_authenticated_user

from django_currentuser.db.models import CurrentUserField


class Category(models.Model):
    name       = models.CharField(max_length=80)
    created_on = models.DateTimeField("Created At", auto_now_add = True, null = True)
    created_by = CurrentUserField(related_name='created_by')
    updated_on = models.DateTimeField("Updated At", auto_now = True, null = True)
    updated_by = CurrentUserField(related_name='updated_by')
    deleted_on = 
    deleted_by = 

def __str__(self):
    return self.name

您可以通过添加布尔值soft_delete对象

   delete =  models.BooleanField(default=False, null=True)

和deleted_by

deleted_by = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE, null=True)

和deleted_on

deleted_on = models.DateTimeField(auto_now_add=True)