【发布时间】:2013-02-27 00:24:33
【问题描述】:
我有很多类是我的数据库模式多态性的一部分。 对于他们中的大多数,我(需要)这样做:
__mapper_args__ = {'polymorphic_identity': unique_integer}
# unique_integer is a unique integer different for each class ex: 10
我想使用装饰器来代替这个,即:
@polid(10)
class ClassName(Inherited):
# instead of repeating for each class the following:
# __mapper_args__ = {'polymorphic_identity': 10}
# I would like to have above decorator or something to do the trick.
pass
我该怎么做?我需要使用什么样的装饰器?以下不起作用(不注册):
def polid(v):
def x(f):
f.__mapper_args__ = {'polymorphic_identity': v}
return f
return x
【问题讨论】:
标签: python python-2.7 sqlalchemy polymorphism