I have played around with django-audit-log for a while, and so far it works great. However, I do need to work on saving the records to a separate db, as Shawn suggested.
Fwiw, there's a page on the wiki about audit trail/logs, which, albeit outdated, should prove helpful. Cheers, AT On 8/10/11, Mike Dewhirst <mi...@dewhirst.com.au> wrote: > On 11/08/2011 9:51am, Shawn Milochik wrote: >> 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. > > I'm sub-classing models.Model to include created, updated and updated_by > fields which is pretty ordinary but nice. I'm also borrowing Marty > Alchin's (Pro Django pp257 - 260) CurrentUserField to automatically > insert the current user into updated_by. > > I used the same technique to subclass models.ForeignKey('Document', > to_field='ancestor' ..) so I can just add AncestorKey() to any model > which needs to link to the "line" of documents rather than a single > document. The project isn't anywhere near finished - I'm still writing > the models - so I don't know how well all this will work - but my thanks > to Marty anyway! > > Also - I just googled and found - > https://bitbucket.org/q/django-simple-history/overview which builds on > Marty Alchin's approach to history. I haven't fully understood his > approach yet so the content of that link is probably a bit beyond me at > the moment. > >> >> 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." > > Beauty indeed :) > > I'm definitely going to rethink my design. You are making me think a > generic solution is worthwhile. > >> >> 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. > > That's something I haven't investigated. I haven't experienced too many > horrors yet. > > Thanks again > > Mike > >> >> 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+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > > -- Sent from my mobile device -- 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+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.