How can I easily mark records as deleted in Django models instead of actually deleting them?

前端 未结 5 915
长发绾君心
长发绾君心 2021-02-02 17:20

Instead of deleting records in my Django application, I want to just mark them as \"deleted\" and have them hidden from my active queries. My main reason to do this is to give

5条回答
  •  情书的邮戳
    2021-02-02 17:44

    Here's a quick blog tutorial from Greg Allard from a couple of years ago, but I implemented it using Django 1.3 and it was great. I added methods to my objects named soft_delete, undelete, and hard_delete, which set self.deleted=True, self.deleted=False, and returned self.delete(), respectively.

    A Django Model Manager for Soft Deleting Records and How to Customize the Django Admin

提交回复
热议问题