我想删除一个模型(House),但在此之前,将其插入已删除的表中。 到目前为止:
@receiver(pre_delete, sender=House)
def delete_house(sender, instance, **kwargs):
reason = kwargs.get('delete_reason', '')
if sender == House:
deleted_house = DeletedHouse(doc_code=instance.doc_code,
tell=instance.tell,
address=instance.address,
delete_reason=reason)
deleted_house.save()
for member in instance.child_set:
m = DeletedMember(first_name=member.first_name,
last_name=member.last_name,
house=deleted_house
)
m.save()
House将删除所有孩子(CASCADE)。所以我必须在pre_delete中保存已删除的房子和孩子。问题是我不知道如何将kwargs中的delete_reason传递给我的方法
答案 0 :(得分:1)
只需将其传递给实例
即可sender == House
如果你在decorator params中设置它,为什么要检查Silent Push Notification
?