更新时间:2022-04-27 09:17:05
您的人员
模型目前不适用于软删除。当您删除 Person
对象时,Django将删除所有相关的帐户
对象。如果要软件删除 Person
对象,请在 Person
模型中添加一个标志。然后,您需要确保您的默认帐户
管理员不包括与软删除的Person对象相关的帐户。
Your Person
model is not currently designed for "soft" deletes. When you delete a Person
object, Django will remove all related Account
objects. If you want to soft-delete Person
objects, add a flag for that in the Person
model. Then you need to make sure that your default Account
manager excludes those accounts that are related to a soft-deleted Person object.
编辑
一种方法是使默认管理器排除与非活动相关的对象人物对象而不是设置它们删除:
One approach is making the default manager exclude the objects related to inactive Person objects instead of setting them "deleted":
class AccountManager(models.Manager):
def get_query_set(self):
return self.filter(person__active=True).filter(active=True)
另一种方法是将Person对象软删除时,将相关的Account对象设置为已删除。为此,您可以使用信号。 后保存信号 on个人对象是合适的我认为。
Another approach would be setting your related Account objects "deleted" when a Person object is soft-deleted. For that, you could use a signal. A post-save signal on Person objects would be appropriate I think.