我有很多类是我的数据库模式多态性的一部分。对于他们中的大多数,我(需要)做:
__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