[SQLObject] fetch instance using column other than ID
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: charles b. <li...@st...> - 2004-03-11 07:37:11
|
Hi List, Sorry for the newbie question, but I'm having a hard time finding the right way to fetch an existing class instance using a different column than id. Assuming the example Person class with an added "email = StringCol()", I am able to fetch based on the email using something like: user = Person.select(Person.q.email=="ab...@xy...", connection=req.conn)[0] but that seems rather unintuitive compared to Person(10) (or Person.get(10) now). I think I'm envisioning an overridden _init but the magic of the metaclass is confusing me on how to implement it. I was also thinking something along the lines of a class function (ie user=Person.lookup("ab...@xy...", req.conn) ) would be nice, but since it is actually being initialized I don't think this is correct. Any ideas/comments? Thanks in advance... -Charles. |