Hello Hello,

I am not quite sure what usage you were looking for but this is pretty
neato.  I pasted it so it was more readable even tho that might be bad
mailing list etiquitte.

A few things to note.  Usually you do item   = ForeignKey('Item')
instead of item_id   = ForeignKey('Item') because that is an item
object not actually an id.  SQLObject creates an id in the table
called item_id but that is all behind the scenes.  I could be wrong if
you are overriding the slqobject default naming scheme but that is the
usual way of doing things.

http://paste.turbogears.org/paste/918

Tell me if that doesn't work or is the wrong way of thinking.

-Ian
On 1/26/07, Tor Hildrum <[EMAIL PROTECTED]> wrote:
>
> I have the following class/relation:
> class Loan(SQLObject):
>   item_id   = ForeignKey('Item')
>   user_id   = ForeignKey('C_users')
>   borrowed  = DateTimeCol(default=datetime.now)
>   delivered = DateTimeCol(default=None)
>
> I want to create a few functions inside this class.
>
> # tells you if an item is borrowed or in stock
> # This can return a True/False value
> def isBorrowed(itemID):
>
> # tells you what user has borrowed something
> # This should return a dict, or a C_Users-object.
> def borrowedTo(itemID):
>
> How would I go about writing functions like this?
> Do, I write something like this:
> def isBorrowed(itemID):
>   foo = self.selectBy(item_id=itemID, delivered<>None)
>
>   # check if foo got a value or not
>
> Can I query a class from within the class? I'm guessing yes :)
>
> Tor
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to