SQLAlchemy - loading user by username
Posted
by
keithjgrant
on Stack Overflow
See other posts from Stack Overflow
or by keithjgrant
Published on 2011-01-16T02:48:48Z
Indexed on
2011/01/16
2:53 UTC
Read the original article
Hit count: 179
Just diving into pylons here, and am trying to get my head around the basics of SQLALchemy. I have figured out how to load a record by id:
user_q = session.query(model.User)
user = user_q.get(user_id)
But how do I query by a specific field (i.e. username)? I assume there is a quick way to do it with the model rather than hand-building the query. I think it has something with the add_column()
function on the query object, but I can't quite figure out how to use it. I've been trying stuff like this, but obviously it doesn't work:
user_q = meta.Session.query(model.User).add_column('username'=user_name)
user = user_q.get()
© Stack Overflow or respective owner