StatType = CompositeType(
'stat',
[
Column('home', Integer),
Column('guest', Integer)
]
)
CardType = CompositeType(
'cards',
[
Column('yellow', StatType),
Column('red', StatType)
]
)
class Referee(Base):
__tablename__ = 'Referee'
id = Column(Integer, primary_key=True)
matches = relationship("FootballMatch", back_populates="referee")
name = Column(String, unique=True)
@aggregated('avg_red', Column(Numeric))
def avg_red(self):
return func.avg(FootballMatch.cards.red.home + FootballMatch.cards.red.guest)
@aggregated('avg_yellow', Column(Numeric))
def avg_yellow(self):
return func.avg(FootballMatch.cards.yellow.home + FootballMatch.cards.yellow.guest)
我正在使用带有 Postgres 的 sqlalchemy-Utils。这个想法很简单,我想汇总裁判每场比赛的平均牌数。但我得到了例外:
Neither 'InstrumentedAttribute' object nor 'Comparator' object associated with FootballMatch.cards has an attribute 'red'
这样的事情可能吗?