Choosing Between AuditTrail and Django-Rcsfield

October 15, 2008. Filed under django 72

Short after posting how to get django-rcsfield running, Marty Alchin posted to mention AuditTrail, and ask if I could see any compelling reasons to use something like django-rcsfield instead of AuditTrail.

If you look at the two, they perform very similar services:

  • django-rcsfield uses a variety of version control systems (Git, Bazaar, Subversion) to maintain a complete version history of a textfield.

  • AuditTrail uses the database to maintain a complete version history of a model (although it doesn't necessarily play well with relations).

Last night I set up an app I am working on to use django-rcsfield, and it took a bit of sleuthing to understand. On the other hand, just now I was able to replace django-rcsfield with AuditTrail in about five minutes. Where rcsfield was opening up weird cross-platform issues related to Git, AuditTrail just worked. Where rcsfield was causing my small vps to lag horribly--again--AuditTrail just worked.

I can imagine some specific situations where having the full power of merging, cloning, branching, etc, would be a real asset, but I suspect such apps are a small minority of all the applications that benefit from some degree of versioning. For those not in that small bucket, AuditTrail seems like the best existing solution.

Setting AuditTrail up was a few short steps:

  1. Paste the code at the bottom of the AuditTrail wiki entry into a file named audit.py, somewhere in your Python path.

  2. Import audit.py in your models.py file.

    from django.db import models
    import audit
    
  3. Add an AuditTrail field to your model definition.

    class MyModel(models.Model):
        title = models.CharField(max_length=200)
        text = models.TextField()
        history = audit.AuditTrail()
    
  4. Sync your database.

    python manage.py syncdb
    
  5. Profit.

    >>> from models import MyModel
    >>> MyModel.create(title="hi",text="some value")
    >>> a = MyModel.objects.all()[0]
    >>> a.text = "some other value"
    >>> a.save()
    >>> a.history.count()
    2
    >>> a.history.all()[0].text
    "some other value"
    >>> a.history.all()[1].text
    "some value"
    

Although I really appreciate the hard work that has gone into django-rcsfield, I think that AuditTrail is simply an easier approach to versioning data at this point in time. I do think there is room in the world for both of these approaches, and that some apps will benefit more from using django-rcsfield than AuditTrail, but I'd recommend starting with AuditTrail and only transitioning over if and when circumstances demand it.

Hopefully both of these projects will continue to improve, but for the time being AuditTrail is the way to go unless you need more advanced VCS functionality like merging, pushing, pulling or cloning.