Django LogEntry to the rescue

If you use Django’s admin application, you’re familiar with its “Recent Actions” sidebar. It gives a simple summary of your latest edits, including clickable links to the relevant objects (not any ones you deleted, naturally, but ones you added or changed).

It’s probably not something you look at very often, unless you do such intensive work in the admin that you lose track of things.

Django stores that log data (via the admin’s LogEntry model) for all admin users, a fact which has caused me to repeatedly daydream about writing a custom view or two to display it. In other words, I’d like to let superusers browse all object editing history. Because sometimes you need to answer questions like “When was that changed?” and/or “Who changed it?”

Today at work, a question arose about some data that was deleted via the admin several months ago. It didn’t need recovering, we just needed a record of its deletion. An audit trail.

LogEntry to the rescue! Via shell and dbshell I was able to do some quick spelunking and get exactly the records we needed.

It was a very positive experience. I love being able answer questions that begin, “Paul, is there any way to…” with: “Yes!” After this, I may even be a little bit closer to writing that code I’ve been daydreaming about.