title: Logging item value changes to Django objects
body: <p>At the moment I'm thinking on how best to implement logging of changes on a Model so as to provide some form of audit trail for the object.</p>
  
  <p>I've looked into django-reversion and to a certain extent it does what I need it to do, however my needs are more simpler than that. I just want something that is able to record which user changed what field on an object when, as well as the previous value of the field before the change was committed.</p>
  
  <p>A simple class to store this would be something like:</p>
  
  <pre><code>class AuditLogEntry(models.Model):
      user = ForeignKey(User, verbose_name=_(u"user"), related_name="actions")
      obj = ForeignKey(ModelToLog, verbose_name=_(u"Model"), related_name="history")
      timestamp = DateTimeField(default=datetime.now)
      field = models.CharField(max_length=64)
      value = models.CharField(max_length=256)
  </code></pre>
  
  <p>At the moment I am thinking of simply adding a block of code in the view handler that updates the model with something like this:</p>
  
  <pre><code>form = ModelToLogForm(request.POST, instance=obj)
  prev_data = dict()
  for changed_field in form.changed_data:
      prev_data[changed_field] = form.instance.get_attribute(changed_field)
  if form.is_valid():
      form.save()
      for changed_field in keys(prev_data):
          obj.history.create(user=request.user, obj=obj, field=changed_field, value=prev_data[changed_field]
  </code></pre>
  
  <p>In theory, it should work, however I keep having the nudging sense that this is not the best way to do it. Is there a better way to do something like this?</p>