I was looking for a way to revert data deleted by mistake from the Django admin.
I reverse-engineered how Django's admin builds the list of objects displayed on the "Are you sure?" confirmation page.
Given a single obj
or list of objs
, the script included in this gist will:
- Use the
NestedObjects
utility to determine the objects that would be deleted - Pass those objects to Django's JSON serializer
- Write the objects to a
deleted-objects
fixture
This allowed me to:
- Restore a database locally to a time before the object was deleted
- Generate the fixture
- Apply the fixture to the database to restore data
is this well tested? I have delete object from production env. by accident and I need to recover it.
I'm afraid to try your script on production.