For now code
.order_by('total DESC')
changes to
.order_by(text('total DESC'))
and you should also import text from sqlalchemy