Django Simple History

3.11.0 · active · verified Fri Apr 10

django-simple-history is a Django library that provides an easy way to store historical records for your Django models, allowing you to view and revert changes through the admin site. It is actively maintained with frequent releases, currently at version 3.11.0.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to add historical tracking to a Django model by simply adding a `history = HistoricalRecords()` field. Remember to add `simple_history` to your `INSTALLED_APPS` and run `makemigrations`/`migrate`. For admin integration, register your model with `SimpleHistoryAdmin`.

import os
from django.db import models
from simple_history.models import HistoricalRecords

# Ensure 'simple_history' is in INSTALLED_APPS in your Django settings.
# Example: INSTALLED_APPS = ['...', 'simple_history', 'myapp']

class Product(models.Model):
    name = models.CharField(max_length=200)
    price = models.DecimalField(max_digits=10, decimal_places=2)
    history = HistoricalRecords()

    def __str__(self):
        return self.name

# To see history in the Django admin:
# 1. Add 'simple_history' to INSTALLED_APPS.
# 2. In myapp/admin.py:
#    from django.contrib import admin
#    from simple_history.admin import SimpleHistoryAdmin
#    from .models import Product
#    admin.site.register(Product, SimpleHistoryAdmin)

view raw JSON →