我有两个column_property
列,我想将它们相加并显示在grandtotal
列中。我希望能够根据grandtotal
列进行排序和筛选。
如何计算subtotal
和shipping
列的值?
代码:
subtotal = orm.column_property(
select([case(
[(func.sum(OrderProductModel.subtotal).is_(None), 0)],
else_=func.sum(OrderProductModel.subtotal))
]).where(OrderProductModel.order_id == id))
shipping = orm.column_property(case(
[(is_expedited.is_(True), shipping_rate)], else_=Decimal(0.00)))
grandtotal = orm.column_property(func.sum(subtotal + shipping))
错误:
TypeError: unsupported operand type(s) for +: 'ColumnProperty' and 'ColumnProperty'
grandtotal
列进行分组。grandtotal = orm.column_property(select([func.sum(subtotal.expression + shipping.expression)]).group_by(id))
- Colton Allen