Re: making history
Mike,
I'm doing something similar in another project. I created a sublass of
models.Model and am using that throughout the project, which makes it
much easier.
On the post-save of any subclass of my custom model, I serialize the
model's fields as a JSON object and store it in a text field of my
application's database in a special audit model. That audit object
stores the timestamp, instance's primary key, and optionally the User
instance that changed it.
There's also a 'description' field in my audit model. For every entry
in the audit table for the same primary key you can grab the JSON and
compare them and write plain text to the description field like 'last
name changed from Smith to Smithe by someguy at 2011-08-10 13:42.'
The beauty of the 'description' field is that if I ever want to change
the format of that, I can change my code and then re-generate the
description from the JSON, so there won't be a cutoff between
"old-style audit history" and "new-style audit history."
Incidentally, my custom model (and therefore all subclasses of it) are
using a UUID as a primary key to avoid the horror that is generic
foreign keys. Just in case you were wondering how my audit scheme
works across various models.
Shawn
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home