Opened 13 years ago
Closed 13 years ago
#16567 closed New feature (wontfix)
Feature Req:"Soft Delete"
Reported by: | Yuchen Ying | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 1.3 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Design decision needed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
It's very common that when we delete items from database, we just mark it as deleted and do a cleanup occasionally. I don't know what the proper name is but I usually call it "soft delete".
Now if you want to add "soft delete" feature in django, you need to:
- Override model.delete()
- Override QuerySet.delete() since bulk delete doesn't call model.delete()
- Override model.Manager.get_query_set() if you want to "hide" deleted items
Well, I think this should be done by django itself :-)
Change History (3)
comment:1 by , 13 years ago
Component: | Uncategorized → Database layer (models, ORM) |
---|---|
Triage Stage: | Unreviewed → Design decision needed |
comment:2 by , 13 years ago
What you really should do to "soft delete", is to just do an update query,
and then do a select with a filter to show objects that are not "deleted".
The only problem with your feature is backwards compatibility.
I also don't think this should be inside the delete function, since human
error can result into unwanted behavior.
A simple update query like:
Entry.objects.filter({conditions go here}).update(deleted=1),
will suffice.
comment:3 by , 13 years ago
Resolution: | → wontfix |
---|---|
Status: | new → closed |
I agree completely that this is a useful pattern: I've implemented it myself a number of times. However, as rvanhoepen says, this is fairly simple to do in your own code, and it's somewhat specialized to CMS-like applications. It's not really appropriate for a built-in part of Django (though as a nice tight third-party app it'd be kinda wonderful).
This is a non-trivial feature. Integrating it in Django probably involves some usability and backwards compatibility tradeoffs. As explained in the contributing guide, this kind of requests should be discussed on django-developers. A ticket here won't gather enough attention.
Also, a patch (or a bitbucket/github branch) with a working prototype would be a big plus to show what you have in mind. Your current proposal is quite vague.
I'm marking this ticket as DDN, but I don't really expect it to happen unless (a) you start a discussion on django-developers (b) you write a patch — at least a draft.