On 24 Jun 2006, at 12:45, Elver Loho wrote:

> class View(SQLObject):
>       ip = UnicodeCol(length = 50)
>       time = DateTimeCol(default = datetime.datetime.now)
>       site = ForeignKey("Page")
>
> What I need is, given a page ID, a data structure holding, for the
> last n days, the date and the number of views on that date.

I had a very similar problem. Since I wanted a count not an object
I found it best to use sqlrepr not View.select()

Some varient of this might do want you need:

from sqlobject.sqlbuilder import *

conn = View.connection
pageid = Page.get(1).id
q = conn.sqlrepr( Select[View.q.siteID, func.COUNT(View.q.ip)],  
groupBy = View.q.siteID,
        where = AND(time >= starttime, time <= endtime, View.q.siteID ==  
pageid) )

or something along those lines (assuming you set starttime + endtime  
suitably).

Disclaimer - this is off the top of my head and hasn't been tested.

See http://www.groovie.org/articles/2005/11/01/how-to-use-database- 
agnostic-sql-in-sqlobject

for more details.

Arthur

-- 
Arthur Clune.                    [EMAIL PROTECTED]
"[Film] only exerts its influence when it stirs patriots up against  
other nations, or  taps into agressive, violent urges" - Hayao Miyazaki




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

Reply via email to