Hi All, I have created a base declarative object that has a pre-made primary key, so I don't have to add it to all my child tables:
class ClassDefaults(DeclarativeMeta): def __init__(cls,classname, bases, dict_): dict_['id'] = Column(Integer, Sequence("id_seq", optional=True), primary_key=True) return DeclarativeMeta.__init__(cls, classname, bases, dict_) Base = declarative_base(metaclass=ClassDefaults) This allows me to create a table as follows, and have an implicit primary key named "id": class UserGroup(Base): __tablename__ = 'usergroup' name = Column(String(80), nullable=False, unique=True, index=True) However, my base class currently uses the *same* sequence for all primary keys. I would like to create a new sequence for each primary key. I was thinking of naming the sequence based on the name of the table, so that UserGroup's sequence would be called "usergroup_id_seq", etc. I am wondering how this is possible, using the above approach, or using Mix-ins, as documented here (Michael Bayer pointed me in this direction) -- http://www.sqlalchemy.org/docs/reference/ext/declarative.html#mix-in-classes While mix-ins look cool, I am not sure how I would reference the __tablename__ of the child class from the Mixin. I can probably work around this by *not* naming the sequences after the table name, but instead use an incrementing global variable to create the unique sequence names, but it seems like a better practice to base the sequence name on the name of the table itself. Michael says that Chris Withers may know how to do this with Mix-ins. Chris, you out there? :) Regards, Daniel -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalch...@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.