= Full History Tracking = [[TOC(inline)]] == Current status == '''Features: almost there''' (21.08.2006) At the moment the contrib.history is quite usefull. Examples below should work. '''NOTE: Comparing and merging should be done by user and is not automated (yet).''' '''WARNING!!! Names of functions may change. Please check this page for any changes.''' === 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/ }}} === TODO === This is a general list of tasks, details are managed in a Basecamp project. If you want access drop me an email at urosDOTtrebecATgmailDOTcom. ||'''Task'''||'''Status'''|| ||Getting the code to work genericaly (on every given model)||'''DONE'''|| ||Getting the code to a working state||'''DONE'''|| ||Getting the API to work as described below||'''DONE'''|| ||Unit tests||(under way)|| ||Author handling (default Anonymous)|| || ||Admin UI integration||(later) || === Discussion === 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. == Introduction == === The problem === 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. == Usage == === Models === 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: {{{ #!python class Post(models.Model): author = models.CharField(maxlength=100) title = models.CharField(maxlength=100) content = models.TextField() date = models.DateField(auto_now=True) class History: pass }}} When this is done every "Post" object will be saved to a "django_history_log" table when created, changed or deleted. === API === For this functionality to be really usefull I need to create some listing, reverting and other functions. '''List of all revisions of an object:''' {{{ #!python from django.contrib.history.models import ChangeLog post = Post(author="Mort", title="Discworld is down!", content="Well, it's rather complicated...") post.save() rev_list = ChangeLog.objects.list_history(post) # Returns a complete list of versions for this object }}} '''List of latest 3 revisions of an object:''' {{{ #!python rev_list = ChangeLog.objects.list_history(post, offset=3) # Returns a list of latest 3 versions for this object }}} '''Get a date-specific list of revisions:''' {{{ #!python rev_list = ChangeLog.objects.version_by_date(post, datetime(2006, 07, 08)) }}} '''Get a revision that is 3 revisions back:''' {{{ #!python rev_list = ChangeLog.objects.get_version(post, offset=3) }}} '''Get a specific revision (for example, 222):''' {{{ #!python rev_list = ChangeLog.objects.get_version(poll, revision=222) }}} '''Revert to a specific revision:''' {{{ #!python # NOT IMPLEMENTED!!! User should do the mreging, comparing and reverting manualy. }}}