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)
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
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
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.