I had to do this last week.

I posted a recipe in this thread:

https://groups.google.com/forum/#!topic/sqlalchemy/Xr1llnf5tzQ


tracked objects inherit from RevisionObject, which adds 2 columns to the 
database:
   revision_id (INT)
   revision_history (HSTORE) 
  
it also adds 2 methods:
    generate_snapshot
    generate_diff

i only track changes on certain elements, so I added a revision_columns 
attribute to the object.  ( which should be a list of the attributes ).

if you wanted all columns, you could just iterate over:

sqlalchemy_orm.class_mapper(self.__class__).mapped_table.c


If you want to go over the relationships, there's another attribute of the 
`mapped_table` that handles that.  OR you could just have both objects 
inherit from something like this and then call generate_diff() on the sub 
objects.

one last note:

I only store data on the first access, on the edits I first store a 
snapshot as r0 , then store a diff as r1.  that cuts down on duplication.


-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to