Thats a mixin class that can be added onto any object inheriting from 
declared_base.   You only need one of the `columns_as_dict` options.  I 
showed 3 variations: one that gives all columns, one that lets you specify 
which columns to include, and another that shows which columns to exclude. 
   You could adjust the defs to return a new object instead of a dict.

I find this solution to be more flexible than using entirely automatic 
properties, because I often have multiple-column primary keys and misc 
columns that are defined by the backend and computed by the application 
(ie, not editable or used by admins or users).  

In your situation you could have a class that does this:

     class YourClassA(Base, Duplicable):
           _columns_notduplicable = ['primary key', 'other private column', 
'another private column']

     class YourClassB(Base, Duplicable):
           _columns_notduplicable = ['primary key', 'other private column', 
'another private column']

     a = YourClassA()
     as_dict = a.columns_as_dict

     a = YourClassB()
     as_dict = b.columns_as_dict

I use something similar when I do Revision Tracking of objects in the 
database -- I call "columns_as_dict" to get a dict of all the relevant 
columns, then serialize that dict to the database with a timestamp.

-- 
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 sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to