如何插入符号(,)以产生SQLAlchemy级别?

时间:2014-06-16 09:15:16

标签: python sqlalchemy

#mapping class 
class Billing(Base):
  __tablename__ = 'billing'
  id = Column(Integer, primary_key=True)
  billingdate= Column(DateTime, nullable=False)
  amt = Column(Integer, nullable=False)
  rate = Column(Integer, nullable=False)
  fk_cpid = Column(Integer, ForeignKey('company.cpid'))

#run
  query = self.mssql_session.query(Billing.billingdate).all()

结果

  

$ 83749283 => $八千三百七十四万九千二百八十三

如何在仅仅SQLAlchemy级别的Billing.billingdate中插入符号(,)?

替换,SubString?

1 个答案:

答案 0 :(得分:1)

from sqlalchemy.ext.hybrid import hybrid_property

class Billing(Base):
    __tablename__ = 'billing'
    id = Column(Integer, primary_key=True)
    billingdate= Column(DateTime, nullable=False)
    _amt = Column(Integer, nullable=False)
    rate = Column(Integer, nullable=False)
    fk_cpid = Column(Integer, ForeignKey('company.cpid'))

    @hybrid_property
    def amt(self):
        return '${:,}'.format(self._amt)

希望,这段代码可以帮到你。