Thank you Luke and Ian! alternateID was exactly what I was looking for. It
always seems so obvious after the fact. :) Would it make sense to mention
it earlier in the docs when talking about fetching instances that already
exist? Something like the following maybe?
"You can use the class method .get() to fetch instances that already exist.
So if you wanted to fetch the Person by id 10, you'd call Person.get(10).
To fetch using data from other unique columns, specify alternateID=True in
that column's initialization and use the class method .by<ColumnName>().
(see alternateID for more detail)"
Ian's lookup class example was also what I had in mind. I think there was
one minor typo in the select that I fixed below, incase others try that.
>
> class Person(SQLObject):
> def lookup(cls, email, connection=None):
> return cls.select(cls.q.email=email, connection=connection)[0]
> lookup = classmethod(lookup)
>
I need to read up on new class styles now.. :) Thanks for the pointers...
-Charles.
|