|Version 4 (modified by 11 years ago) (diff),|
Full History Tracking
Feature incomplete''' (15.07.2006)
At this stage none of the samples below work. Code is experimental and does not work. This status will change as soon as I get the API and the generic functions working.
Get the code
You can grab the current code from the "full-history" branch:
svn co http://code.djangoproject.com/svn/django/branches/full-history/
This is a general list of tasks, details are managed in a Basecamp project. If you want access drop me an email at urosDOTtrebecATgmailDOTcom.
|Getting the code to work genericaly (on every given model)|
|Getting the API to work as described below|
|Getting the code to a working state|
The changelog-type of history in its current implementation, would write log only when using Admin and log would include only information about the change but not the content that was changed. This is not very usefull when you would like to revert a change or even see what whas changed.
The main idea
I am trying to write a different implemetation that will be independent of Admin and will store the content as well. This way developers will be able to save, compare and revert any changes made in any particular model.
How to enable history tracking? Enablig history tracking for a particural model is just like adding Admin functionality - add an inner class as shown below:
class Post(models.Model): author = models.CharField(maxlength=100) title = models.CharField(maxlength=100) content = models.TextField() date = models.dateField() class History: pass
When this is done every "Post" object will be saved to a "appname_history" table when created, changed or deleted.
For this functionality to be really usefull I need to create some listing, reverting and other functions.
Listing all revisions of an object:
rev_list = poll1.revisions.all()
Get a date-specific list of revisions:
rev_list = poll1.revisions.by_date(datetime(2006, 07, 08))
Get a revision that is 3 revisions back:
rev_list = poll1.revisions.get(offset=3)
Get a specific revision (for example, 222):
rev_list = poll1.revisions.get(id=222)
Revert to a specific revision:
poll1 = poll1.revisions.revert_to(id=222)
The ability to keep previous states of a table accessible is well described in Richard T. Snodgrass's (http://www.cs.arizona.edu/~rts/) "Developing Time-Oriented Database Applications in SQL" (http://www.cs.arizona.edu/people/rts/tdbbook.pdf). Adding the ability to designate a particular model as a transaction-time state table, with suitable methods added to the model's API, and with all queries defaulting to using either the current time or the latest time.