我想对混合属性中的id进行一些格式化,以便10以下的数字以P0(P01、P02、03等)作为前缀。下面的代码从elements.py中的__bool__
方法抛出一个TypeError: Boolean value of this clause is not defined
。我错过了什么
在my models.py中:
@hybrid_property
def conversion_number(self):
return 'P0{}'.format(self.id) if self.id < 10 else 'P{}'.format(self.id)
这是我的解决办法:
问题似乎是,当sqlalchemy初始化模型时,id是InstrumentedAttribute(不是int)。这种行为很奇怪,因为我的实现与SQLAlchemy文档中的example没有本质上的区别
相关问题 更多 >
编程相关推荐