- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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 settings.py.
Setup your urls.py and install the django-reversion module −
pip install django-reversion
In settings.py, add the following line −
INSTALLED_APPS = ['reversion']
I will not go to views.py and urls.py because they are not important for this task.
Now in models.py, add the following lines −
from django.db import models # Create your models here. class Data(models.Model): Name=models.CharField(max_length=100) salary = models.CharField(max_length=20)
Here we created a Django model on which we are going to apply reversion.
In admin.py −
from django.contrib import admin from .models import Data from reversion.admin import VersionAdmin @admin.register(Data) class ClientModelAdmin(VersionAdmin): pass
Here we created a reversion admin which we registered for the model named Data.
Now on the terminal, run the following commands −
python manage.py createinitialrevisions python manage.py makemigrations python manage.py migrate
It will create a reversion and then make migrations and migrate.
Now you can proceed to check the output −
In http://127.0.0.1/admin and on Datas model admin −
- Exporting models data in Django
- Adding JSON field in Django models
- Importing data into models in Django
- Making a Pickle field in Django models
- How to implement django-material in your Django project?
- Early Database Models
- Multi-Threading Models
- Reliability Growth Models
- Form widget in Django
- Google Authentication in Django
- Smooth profiling in Django
- Implementing Stacks in C#
- Implementing Photomosaics in Python
- Reference Models in Computer Network
- Evolution of Data Models