On Jul 23, 2010, at 2:07 PM, cropr wrote: > I am trying to add a Column definition using a metaclass but things > aren't working as expected > > I am using something like the code below > > class MyMeta(DeclarativeMeta): > def __init__(cls, name, bases, attrdict): > setattr(cls, 'title', Column(types.String(80)) > DeclarativeMeta.__init__(cls, name, bases, attrdict) > > Base = declarative_base(metaclass=MyMeta) > > class BasicModel(Base): > __tablename__ = 'basic' > > id = Column(types.Integer, primary_key=True, autoincrement=True) > identifier = Column(types.String(40)) > > but the title Column does not seems to be included in the BasicModel > class. > Any idea what's wrong?
Use regular mixins. See http://www.sqlalchemy.org/docs/reference/ext/declarative.html#mixin-classes . If for some reason you don't want to do that, using your recipe above, add the column to attrdict. See http://www.sqlalchemy.org/trac/wiki/UsageRecipes/DeclarativeMixins for an example. -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
