由于我从不想真正删除USER (BASE)
个对象,因此我在delete_date
模型上引入了BASE
:
class BASE (models.Model):
class Meta:
abstract = True
app_label = 'base'
verbose_name_plural = 'bases'
objects = BASE_MANAGER ()
insert_date = models.DateTimeField (default = datetime.now (), auto_now_add = True)
update_date = models.DateTimeField (default = datetime.now (), auto_now = True)
delete_date = models.DateTimeField (null = True, blank = True)
def save (self):
super (BASE, self).save ()
def delete (self):
if not self.delete_date:
self.update_date = datetime.now ()
self.delete_date = datetime.now ()
self.save ()
else:
pass ## no delete!
现在因为我没有在super (BASE, self).delete ()
中包含BASE.delete
,所以没有执行实际的SQL,这很好;不幸的是,这也阻止了外键的级联。在Django中有没有一种优雅的方法来实现这一目标?
答案 0 :(得分:0)
我想我已经找到了我一直在寻找的答案,因为显然用于描述我的用例的实际术语是在soft delete cascading实施的soft delete implementation中描述的“软删除”。
我会看看那个;仍然感谢你的回复。 :)