|Version 3 (modified by anonymous, 8 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)