[sqlalchemy] Relate to Object by Two Refs

2013-05-15 Thread Ji Zhang
Hi, Say I have a Request model and User model: class Request(Base): id = Column(Integer, primary_key=True) user_id = Column(Integer) admin_id = Column(Integer) class User(Base): id = Column(Integer, primary_key=True) username = Column(String) The Request is created by a user (User)

[sqlalchemy] How to Use Alias in ORDER BY Caluse?

2013-01-07 Thread Ji Zhang
Hi, My SQL is like select host, count(*) as cnt from tbl group by host order by cnt desc How to achieve this using ORM? session.query(Tbl.host, func.count('*').label('cnt')).group_by(Tbl.host).order_by(???) I don't wanna type again func.count... in order_by(). Thanks. -- You received this

Re: [sqlalchemy] How to Use Alias in ORDER BY Caluse?

2013-01-07 Thread Ji Zhang
The second one is neat. Thanks~ On Tuesday, January 8, 2013 11:28:34 AM UTC+8, Michael Bayer wrote: On Jan 7, 2013, at 9:19 PM, Ji Zhang wrote: Hi, My SQL is like select host, count(*) as cnt from tbl group by host order by cnt desc How to achieve this using ORM

[sqlalchemy] How to Get the Mapped Class's Table Name

2012-10-23 Thread Ji Zhang
Hi, I need to mapper a class to table which contains a dynamic table name like tbl_data_20121023. When writing the __repr__ method, I want to print out the mapped table name. How to do that? def __repr__(self): return '%s: %s %s' % (self.???tablename???, self.field1, self.field2) Thanks.