Provides a model mixin to allow objects to be "trashed" before finally deleted.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


UnDelete is a simple project that gives you access to a TrashableMixin meta model and some useful managers as well.

Much of the work is heavily derivative of Nathan Ostgard's post on the same topic.


In three easy steps!

  1. Place 'undelete' in your installed apps.

  2. Add:

     from undelete.models import TrashableMixin
  3. Make sure your model inherits the mixin:

     class YourMode(TrashableMixin): ...

And you're done. You should now be able to query trashed items with the "trash" manager and non-trashed items with the usual objects manager.

You can now install django-undelete using pip, for example:

    pip install git+

See the section below for a more through explanation.


With the steps above taken, managing trashed items is fairly straightforward:

>>> YourModel.objects.count()
>>> YourModel.trash.count()
>>> obj = YourModel.objects.get(pk=1)
>>> obj
< YourModel: u'Test object' >
>>> obj.delete()
>>> obj
< YourModel: u'Test object (trashed)' >
>>> YourModel.objects.count()
>>> YourModel.trash.count()
>>> obj.restore()
>>> obj
< YourModel: u'Test object' >
# Call delete twice and she's gone...
>>> obj.delete()
>>> obj.delete()
# You can also skip the trash entierely
>>> obj = YourModel.objects.get(pk=1)
>>> obj.delete(trash=False)

Future plans also call for a management command to delete everything trashed a certain period of time ago. Stay tuned!

Changelist from v0.0.0 to v1.0.0

  • Implemented TrashableQuerySet so that also bulk deletes of QuerySets will trigger the special TrashableMixin delete() for soft deletion.
  • Created file so that this can be easily installed with pip or easy_install.
  • Number of smaller code fixes.