[Fixed]-Django – Allowing super user to review all interactions to the database and generate reports

1👍

django-reversion is an app that allows for a few of the things you are looking for:

  • Roll back to any point in a model instance’s history.
  • Recover deleted model instances.
  • Simple admin integration.

Setup is easy; add to INSTALLED_APPS and migrate, then subclass the VersionAdmin class provided. The app itself creates db tables of all actions performed, who performed them, when, and serialized representations of the model that can be restored. Setup is that easy, no need to override models or go hog wild.

from django.contrib import admin
from reversion.admin import VersionAdmin

@admin.register(YourModel)
class YourModelAdmin(VersionAdmin):
    pass

You will have to create your own AdminAction for reports, but can use the bundled VersionQuerySet class to retrieve all revisions for a given model. This is easy enough, especially when using Django AdminActions

for revision in Version.objects.get_for_model(model, model_db=None):
    output_contents += '|'.join([str(revision.model), revision.user])
    output_contents += '\r\n'

Somewhat related is django-moderation, where you register a model w/ a hook and then can require moderation for model objects. Take a look at the additional Manager methods you get when using this:

>>> MyModel.objects.all().approved()     # approved by moderator
>>> MyModel.objects.all().pending()      # pending in moderation queue
>>> MyModel.objects.all().rejected()     # rejected by moderator
>>> MyModel.objects.all().flagged()      # flagged
>>> MyModel.objects.all().not_flagged()  # not flagged

Objects changed by a non-moderator are placed in a queue and approved/rejected via the admin.

These two can work together and should cover your needs when used in tandem.

Leave a comment