avdd wrote:
In a metaclass's __init__, the attributes have already been placed on
the class, so mutating the attributes dict has no effect.
Spot on. SA fudged this prior to 0.6beta so you could get away with
shoving stuff in dict_, you now can't...
def PrimaryKey(seqprefix):
return Column(Integer, Sequence(seqprefix, optional=True),
primary_key=True)
class ClassDefaults(DeclarativeMeta):
def __init__(cls,classname, bases, dict_):
seqprefix = getattr(cls,'__tablename__',None)
When are you expecting cls not to have a tablename?
Using tabs for intentation is evil.
dict_['id'] = PrimaryKey(seqprefix=seqprefix)
Why not just have:
cls.id = Column(Integer, Sequence(cls.__tablename__, optional=True),
primary_key=True)
?
You might also benefit from reading:
http://www.sqlalchemy.org/docs/reference/ext/declarative.html#mix-in-classes
...I don't think they'll help here 'cos you're computing based on
__tablename__.
Of course, nowadays, I tend to have tablename computed in a mix-in that
does all my common stuff:
class BaseMixin(object):
__table_args__ = {'mysql_engine':'InnoDB'}
@classproperty
def __tablename__(cls):
return cls.__name__.lower()
id = Column(Integer,primary_key=True)
cheers,
Chris
--
Simplistix - Content Management, Batch Processing & Python Consulting
- http://www.simplistix.co.uk
--
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.