开发者

Sqlalchemy: Get some columns aliased

开发者 https://www.devze.com 2023-03-05 01:05 出处:网络
I have a question that I\'m sure it\'s very quick to answer, but I haven\'t been able to find it googling...

I have a question that I'm sure it's very quick to answer, but I haven't been able to find it googling...

I have a class Product defined with declarative SqlAlchemy:

class Product(declarativeBase):
    __tablename__ = "products"
    _brand = Column("brand", Unicode(128))
    _series = Column("series", String(128))
    _price =开发者_运维百科 Column("price", Float)
    _description = Column("description", UnicodeText)

    _manufacturerId = Column("manufacturer_id", Integer, ForeignKey("manufacturers.id"), key="manufacturerId")
    _manufacturer = relationship("Manufacturer",
        uselist=False,
         backref=backref("_products", collection_class=set)
         )

And a a certain point, I want to get some columns of all the Products, such as _brand and _manufacturerId, but instead of retrieving it named _manufacturerId I want it called _manufacturer (mainly to "hide" the relationship thing).

I don't know how to do that... It would be something like:

session.query(Product.Product._brand, Product.Product._manufacturerId as "_manufacturer").all()

I'm pretty sure that is doable, but I don't know how (using sqlalchemy 0.6.6, just in case it's relevant)

Thank you very much!


Actually... I think "label" may work.

How do I put a SQLAlchemy label on the result of an arithmetic expression?

If it does, I'll detail it here

0

精彩评论

暂无评论...
验证码 换一张
取 消