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
@i-salameh95: I would recommend testing this in a local or staging environment first.
The steps would be to:
deleted-objects.json
fixtureThe point of this Gist is to avoid restoring a backup into the production environment to "recover" the deleted objects.