I know there is reversion out there, I know there is fullhistory branch in django. BUT I would VERY much like to stick with original history of django objects. I just simply need to make sure I also save OLD and NEW values.
By default django just saves WHAT happened (e.g. update) but doesnt store the values. Anybody can point me to something (snippet or app) that slightly enhances the default history of django and stores also the values of edited attributes not just the fact that it was edited.
Now My history says
9-01-2012 12:55:02 chnaged: time
I want it to say
9-01-2012 12:55:02 chnaged: time from 6 to 8
UPDATE: ==> for anyone interested in my solution (based on answer below)..
-
Added HistoryModel(object) class to my models.py
class HistoryModel(object): changed_fields = {} -
Inherited in any of my models
-
Added a pre_save receiver to save old values:
@receiver(pre_save, sender=Customer) def save_old_values(sender,**kwargs): #dont delete using in eval db_obj = sender.objects.get(pk=kwargs['instance'].pk) for field in kwargs['instance']._meta.fields: if not eval("db_obj." + str(field.get_attname_column()[0])) == eval("kwargs['instance']." + str(field.get_attname_column()[0])): kwargs['instance'].changed_fields[field.get_attname_column()[0]] = "from "+str(eval("db_obj." + str(field.get_attname_column()[0]))) + " to " + str(eval("kwargs['instance']." + str(field.get_attname_column()[0]))) -
Overwrote the log_change method in my admin and collected object.changed_fields dict and stored it as a message
It’s not ‘default django’. You are using a contributed django application (the admin) so it’s an app like any other (i.e. django-reversion) and to that extent, it doesn’t support the feature you have in mind out of the box.
Luckily, the django admin is quite configurable. You could try overwriting the
log_changemethod of yourModelAdminclass and making thechange_messagemore verbose by detecting which fields have changed (by comparing the form values against the database values). Presumably you want this functionality across all apps in your project, so could either write a mixin to support this, or fork the entire admin and hardcode the functionality.