[web2py] Re: how to use sum() in grid

2017-07-28 Thread Massimo Di Pierro
There is no easy way but I just made a commit that fixes your problem. If you use trunk or wait for a next web2py version (within days) and you can do: def stck_issue_manage(): #form = SQLFORM.smartgrid(db.t_stck_issue,onupdate=auth.archive) grid = SQLFORM.grid(db.t_stck_issue) if gr

Re: [web2py] Re: How to use SUM()

2010-03-09 Thread Thadeus Burgess
You raise a good point. If the calculations are done database side then I suppose it is worth the difficulty in syntax. I just wish the syntax was more natural. -Thadeus On Tue, Mar 9, 2010 at 9:54 PM, mdipierro wrote: > I disagree. In the case you are proposing, the computation would be >

[web2py] Re: How to use SUM()

2010-03-09 Thread mdipierro
I disagree. In the case you are proposing, the computation would be done web2py site since you are fetching all rows. In the current implementation you can do s=(db.some_table.amount.sum() +db.some_table.amount.min())*(db.some_table.amount.max()+3) row = db(...).select(s).first() answer = row[s]

[web2py] Re: How to use SUM()

2010-03-09 Thread mr.freeze
Ah, this makes more sense now. On Mar 9, 9:03 pm, mdipierro wrote: > s=db.some_table.amount.sum() > row = db(...).select(s).first() > answer = row[s] > > On Mar 9, 8:23 pm, Thadeus Burgess wrote: > > > Is it just me or is this archaic? > > > -Thadeus > > > On Tue, Mar 9, 2010 at 6:48 PM, Russell

Re: [web2py] Re: How to use SUM()

2010-03-09 Thread Thadeus Burgess
Still doesn't seem natural. db(...).select().sum(db.table.field) seems much more natural. rows = db(db.table.id > 0).select(orderby=~db.table.datetimestamp) total_hours = rows.sum(db.table.hours_worked) avg_hours = rows.avg(db.table.hours_worked) Would the actual implementation of this be d

[web2py] Re: How to use SUM()

2010-03-09 Thread mdipierro
s=db.some_table.amount.sum() row = db(...).select(s).first() answer = row[s] On Mar 9, 8:23 pm, Thadeus Burgess wrote: > Is it just me or is this archaic? > > -Thadeus > > On Tue, Mar 9, 2010 at 6:48 PM, Russell wrote: > > The number is stored in a dictionary called '_extra'.  The top part of >

[web2py] Re: How to use SUM()

2010-03-09 Thread mr.freeze
It's not just you. On Mar 9, 8:23 pm, Thadeus Burgess wrote: > Is it just me or is this archaic? > > -Thadeus > > On Tue, Mar 9, 2010 at 6:48 PM, Russell wrote: > > The number is stored in a dictionary called '_extra'.  The top part of > > what you are getting is the dictionary key.  Do somethin

Re: [web2py] Re: How to use SUM()

2010-03-09 Thread Thadeus Burgess
Is it just me or is this archaic? -Thadeus On Tue, Mar 9, 2010 at 6:48 PM, Russell wrote: > The number is stored in a dictionary called '_extra'.  The top part of > what you are getting is the dictionary key.  Do something like this to > get just the number... > > row = db(...).select(db.som

[web2py] Re: How to use SUM()

2010-03-09 Thread Russell
The number is stored in a dictionary called '_extra'. The top part of what you are getting is the dictionary key. Do something like this to get just the number... row = db(...).select(db.some_table.amount.sum())[0] answer = row.'_extra['SUM(some_table.amount) '] See pg 169 of the book. On Mar

[web2py] Re: How to use SUM()

2010-03-09 Thread mdipierro
rows=db(...).select(db.some_table.amount.sum()) print rows.first()[db.some_table.amount.sum()] On Mar 9, 6:23 pm, minh wrote: > I couldn't find much documentation on sum() and I'm not sure how to > use it. > > If I have something like > > define_table('some_table', >    Field('amount', 'integer')