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'm really glad you left a comment...I had a need for this Gist again this week and probably wouldn't have remembered that I had wrote it without getting your comment notification.
The Gist still works...I may try and update it or even re-package it into a more full-featured library down the road.
Best,