Shortcuts when using django-reversion in views.


Wrap every request in a revision block.

The request user will also be added to the revision metadata.

To enable RevisionMiddleware, add 'reversion.middleware.RevisionMiddleware' to your MIDDLEWARE_CLASSES setting. For Django >= 1.10, add it to your MIDDLEWARE setting.


This will wrap every request that meets the specified criterion in a database transaction. For best performance, consider marking individual views instead.

RevisionMiddleware.manage_manually = False

If True, versions will not be saved when a model’s save() method is called. This allows version control to be switched off for a given revision block.

RevisionMiddleware.using = None

The database to save the revision data. The revision block will be wrapped in a transaction using this database. If None, the default database for reversion.models.Revision will be used.

RevisionMiddleware.atomic = True

If True, the revision block will be wrapped in a transaction.atomic().


By default, any request that isn’t GET, HEAD or OPTIONS will be wrapped in a revision block. Override this method if you need to apply a custom rule.

For example:

from reversion.middleware import RevisionMiddleware

class BypassRevisionMiddleware(RevisionMiddleware):

    def request_creates_revision(self, request):
        # Bypass the revision according to some header
        silent = request.META.get("HTTP_X_NOREVISION", "false")
        return super().request_creates_revision(request) and \
            silent != "true"