On Oct 17, 2011, at 5:40 AM, Robert Forkel wrote:

> Hi all,
> Using sqlalchemy 0.7.2 I created a couple of mixin classes (say Mixin)
> to share columns declarations between model classes (say A and B).
> Sometimes I have to create instances of type B initialized with the
> values of an existing object of type A for the columns declared by
> Mixin. I'd like to make this code extensible with respect to the
> columns declared in Mixin, i.e. adding new columns to Mixin should
> require updating this code.
> Is there a way to find the names of column properties contributed by a
> Mixin?
> (I tried with checking Mixin.__dict__ for items of type
> sqlalchemy.schema.Column, but this doesn't give foreign keys declared
> via @declared_attr)
> best regards
> robert

the mixin is pretty much what you see there, a Python class with some 
attributes.  @declared_attr doesn't do anything except allow the function to 
act like an attribute at the class level (it's just one line), and also is a 
"marker" object recognized by Declarative.   So if you wanted to see what a 
certain attribute had, you'd call it, that is, instead of looking in __dict__, 
you'd say:

for attr in dir(MyMixin):
    value = getattr(MyMixin, attr)
    # inspect "value"


-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to