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

2024-03-28 20:54:37 发布

您现在位置:Python中文网/ 问答频道 /正文

#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 => $83,749,283

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

替换,子字符串


Tags: idfalsebasecolumnintegerquerymappingclass
1条回答
网友
1楼 · 发布于 2024-03-28 20:54:37
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)

希望,这个代码能帮到你

相关问题 更多 >