Implementing models reversion in Django

In this article, we are going to learn how to add object's data tracking, deleted data recovery and recovery in objects. Reversion means getting back your deleted model data, it will recover all of your deleted data in a single click and it even gives tracking of each model object.

First create a Django project and an app and add app inINSTALLED_APPS in

Setup your and install the django-reversion module −

pip install django-reversion

In, add the following line −

INSTALLED_APPS = ['reversion']


I will not go to and because they are not important for this task.

Now in, add the following lines −

from django.db import models

# Create your models here.
class Data(models.Model):
   salary = models.CharField(max_length=20)

Here we created a Django model on which we are going to apply reversion.


from django.contrib import admin
from .models import Data
from reversion.admin import VersionAdmin
class ClientModelAdmin(VersionAdmin):

Here we created a reversion admin which we registered for the model named Data.

Now on the terminal, run the following commands −

python createinitialrevisions
python makemigrations
python migrate

It will create a reversion and then make migrations and migrate.

Now you can proceed to check the output −


In and on Datas model admin −