From AuditTrail, I have this model definition:
from django.db import models
import audit
import random
def some_callback(instance):
return `random.randrange(1, 99)` + 'trackable_val'
class Person(models.Model):
first_name = models.CharField(max_length=255)
last_name = models.CharField(max_length=255)
salary = models.PositiveIntegerField()
history = audit.AuditTrail(track_fields=(('extra_1', models.CharField(max_length=30), 'hardcoded_value'), ('extra_2', models.CharField(max_length=30), some_callback),))
def __str__(self):
return "%s %s" % (self.first_name, self.last_name)
How could I code the option to save some string in the audit? The way I think, if I knew how/where to pass the string with the username to the AuditTrail constructor that could solve my problem. I would like to add the request.user
as argument of some_callback
.
However in its current form, the callback doesn't accept parameters. Besides I don't know how to pass the string with the username to the Person constructor.
This is becoming more complicated of what I thought initially. That say me it's likely that I'm doing something wrong... What do you think?