Skip to main content

Store model history and view/revert changes from admin site.

Project description

django-simple-history

https://secure.travis-ci.org/treyhunner/django-simple-history.png?branch=master https://coveralls.io/repos/treyhunner/django-simple-history/badge.png?branch=master

django-simple-history is a tool to store state of DB objects on every create/update/delete.

Install

Install from PyPI with pip:

$ pip install django-simple-history

Basic usage

Using this package is _really_ simple; you just have to import HistoricalRecords and create an instance of it on every model you want to historically track.

On your models you need to include the following line at the top:

from simple_history.models import HistoricalRecords

Then in your model class, include the following line:

history = HistoricalRecords()

Then from either the model class or from an instance, you can access history.all() which will give you either every history item of the class, or every history item of the specific instance.

Example

Models:

class Poll(models.Model):
    question = models.CharField(max_length = 200)
    pub_date = models.DateTimeField('date published')

    history = HistoricalRecords()

class Choice(models.Model):
    poll = models.ForeignKey(Poll)
    choice = models.CharField(max_length=200)
    votes = models.IntegerField()

    history = HistoricalRecords()

Usage:

>>> from poll.models import Poll, Choice
>>> Poll.objects.all()
[]
>>> import datetime
>>> p = Poll(question="what's up?", pub_date=datetime.datetime.now())
>>> p.save()
>>> p
<Poll: Poll object>
>>> p.history.all()
[<HistoricalPoll: Poll object as of 2010-10-25 18:03:29.855689>]
>>> p.pub_date = datetime.datetime(2007,4,1,0,0)
>>> p.save()
>>> p.history.all()
[<HistoricalPoll: Poll object as of 2010-10-25 18:04:13.814128>, <HistoricalPoll: Poll object as of 2010-10-25 18:03:29.855689>]
>>> p.choice_set.create(choice='Not Much', votes=0)
<Choice: Choice object>
>>> p.choice_set.create(choice='The sky', votes=0)
<Choice: Choice object>
>>> c = p.choice_set.create(choice='Just hacking again', votes=0)
>>> c.poll
<Poll: Poll object>
>>> c.history.all()
[<HistoricalChoice: Choice object as of 2010-10-25 18:05:30.160595>]
>>> Choice.history
<simple_history.manager.HistoryManager object at 0x1cc4290>
>>> Choice.history.all()
[<HistoricalChoice: Choice object as of 2010-10-25 18:05:30.160595>, <HistoricalChoice: Choice object as of 2010-10-25 18:05:12.183340>, <HistoricalChoice: Choice object as of 2010-10-25 18:04:59.047351>]

CHANGES

1.2.3 (2013-04-22)

  • Fixed packaging bug: added admin template files to PyPI package

1.2.1 (2013-04-22)

  • Added tests

  • Added history view/revert feature in admin interface

  • Various fixes and improvements

Oct 22, 2010

  • Merged setup.py from Klaas van Schelven - Thanks!

Feb 21, 2010

  • Initial project creation, with changes to support ForeignKey relations.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-simple-history-1.2.3.tar.gz (11.9 kB view details)

Uploaded Source

File details

Details for the file django-simple-history-1.2.3.tar.gz.

File metadata

File hashes

Hashes for django-simple-history-1.2.3.tar.gz
Algorithm Hash digest
SHA256 1a40037b33ceabe2cf6d0b2e2e21dad2133f590029e970eed012727c07e85d78
MD5 007efdcd46f9dc6baf93b3089ab51d7d
BLAKE2b-256 d99959fc7b8b560d9b12e24e48c0736c9dab6ec44de6cde5255e397d4df24fc4

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page