Ben Sizer schreef:
now = datetime.datetime.now()
output = []
users = LibraryUser.select(Loan.q.expiry > now) # only get relevant
users
for user in users:
   for loan in user.loans: # at least one of these is overdue
       if loan.expiry > now:
           output.append(user, loan, loan.book)

expired_loans = Loan.select(Loan.q.expire>func.NOW())
output = [loan.user, loan for loan in expired_loans]

This would genereate n+1 queries which shoudn't be to bad depending on
how many expired loans there are ;).

The output you want doesn't follow the one-row per instance pattern on
which SQLObject is build. SQLAlchemy allows you to map class instances
to queries, thus it might be better suited.

However, I'm guesing that you only use this query to represent this in
a datagrid. In this case you could just write the query using the
SQLBuilder syntax and dump the resulting tuples into the datagrid:
query = select( [User.q.name, loan.q.epired_on, loan.q.book], AND(
User.q.id==Loan.q.userID, Loan.q.expire>func.NOW()) )


--~--~---------~--~----~------------~-------~--~----~
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