是否可以在SQLAlchemy模型中创建类似“hybrid collumn”的东西?
当我有以下型号时:
from sqlalchemy.ext.hybrid import hybrid_property
class User(Base):
__tablename__ = 'user'
id = Column(Integer, primary_key=True)
firstname = Column(String(50))
lastname = Column(String(50))
# i tried both, hybrid_property and hybrid_method but nothing works in my case
@hybrid_property
def fullname(self):
return self.firstname + " " + self.lastname
然后我想在查询中使用这个混合列,如:
db.query(User.fullname).filter(...)
感谢。