Django: auditing models and recording admin usage
===

I'm trying to find the best way to audit some models in my Django project. To provide some context: the website has Accounts, Projects, and Users. Any of these can be marked as active or inactive. When the active state of the item changes I want to record the date and the user name of the staff member that changed it.

I've looked at several approaches to solving this auditing problem, but I'm hoping the StackOverflow community can point me to some better solutions. Django's built in history for the admin interface has a nice format, but isn't nearly detailed enough. It only tells me that an item has changed, but not what state it was set to:

![enter image description here][1]

I would love to use Django's built in history if I could change the Action message and only record actions for certain fields (while excluding others).

My next attempt to solve this auditing problem was looking into addons. Django Reversion seems to be the most popular, but I don't need most of the features it has and it's really geared towards version control rather than auditing. I also found one addon called AuditTrail, but it's very primitive.

After trying these possibilities I attempted to roll my own auditing code. I created a new model to record activity. An entry is written every time an Account, Project, or User is activated/deactivated.

    class ActivityHistory(models.Model):
        """
        Stores the history of when accounts, projects, and users are active.
        This class uses generic relations in order to point to any model type.
        For more information see: https://docs.djangoproject.com/en/dev/ref/contrib/contenttypes/#generic-relations
        """
        content_type = models.ForeignKey(ContentType)
        object_id = models.PositiveIntegerField()
        content_object = generic.GenericForeignKey('content_type', 'object_id')
        active = models.BooleanField(help_text="The target state (true if the item was activated, false if it was deactivated).")
        date = models.DateTimeField(help_text="The time at which the active state was changed.")
        actor = models.ForeignKey(User, help_text="The staff member who changed the active state of the account, project, or user in question.")
        class Meta:
            ordering = ['-date']

The problem with this is that I have to record the information using signals. Inside a signal handler I don't have access to the HTTP `request` object. So how can I record which staff member changed the item in question?

Are there other solutions to this problem that would be easier to implement?

  [1]: http://i.stack.imgur.com/HMvFt.png