Opened 4 years ago

Closed 4 years ago

#16567 closed New feature (wontfix)

Feature Req:"Soft Delete"

Reported by: yegle 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:

  1. Override model.delete()
  2. Override QuerySet.delete() since bulk delete doesn't call model.delete()
  3. 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 Changed 4 years ago by aaugustin

  • Component changed from Uncategorized to Database layer (models, ORM)
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Design decision needed

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.

comment:2 Changed 4 years ago by rvanhoepen

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 Changed 4 years ago by jacob

  • Resolution set to wontfix
  • Status changed from new to 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).

Note: See TracTickets for help on using tickets.
Back to Top