On Oct 30, 2013, at 1:43 PM, jkmacc <jkm...@gmail.com> wrote: > > Hmm... The 'schema' problem was my dumb mistake, but I still haven't found a > use of @declared_attr that solves my problem. It looks like, by the time I > get to my OldStudents or anything afterwards, I have to redeclare almost > everything in __table_args__. I've tried modifying the base with a > @declared_attr that merges __table_args__ down the class hierarchy, like in > https://groups.google.com/forum/#!topic/sqlalchemy/KybuUktY3t8, but I just > get recursion problems. I'd hoped that I could declare most everything once > in the abstract class, but it seems that what you're saying is that this > isn't true.
I’m not seeing that as the case, I can apply the @declared_attr just to the top __table_args__ and that’s all that’s needed, everything works out fine: from sqlalchemy import Column, Numeric, String, Date, PrimaryKeyConstraint from sqlalchemy.ext.declarative import declarative_base, declared_attr Base = declarative_base() class Students(Base): __abstract__ = True @declared_attr def __table_args__(cls): return (PrimaryKeyConstraint(u'stid', u'last_name'),) stid = Column(Numeric(9, 0, False), nullable=False, info={'format': '9.2f'}) first_name = Column(String(30), info={'format': '30.30s'}) last_name = Column(String(30), info={'format': '30.30s'}) description = Column(String(80), info={'format': '80.80s'}) lddate = Column(Date, info={'format': '%Y-%m-%d %H:%M:%S'}) class MyStudents(Students): __tablename__ = 'students' __table_args__ = Students.__table_args__ + ({'schema': 'me'},) class OldStudents(Students): __tablename__ = 'oldstudents' __table_args__ = Students.__table_args__ + ({'schema': 'me'},) class OtherStudents(Students): __tablename__ = 'students' __table_args__ = Students.__table_args__ + ({'schema': 'other'},) # schema works assert OtherStudents.__table__.schema == “other" # primary key works assert list(OtherStudents.__table__.primary_key) == \ [OtherStudents.__table__.c.stid, OtherStudents.__table__.c.last_name] # what’s not working? -- 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/groups/opt_out.