Now work!!
the code is:
submenus = db.menus.with_alias('menusoptions')
query = (db.menus.parent_id == 0)
count = submenus.id.count()
# bad hack
count.tablename = 'menus'
count.readable = True
count.represent = False
count.formatter = lambda value:value
count.label = T('count')
count.table = db.menus
# end bad hack
table = SQLFORM.grid(query,
fields = [
db.menus.id,
db.menus.title,
count,
],
left=submenus.on(db.menus.id ==
submenus.parent_id),
groupby=db.menus.id,
)
end code.
Add the possibility of fields count, sum ... without the "bad hack" could bea
improvement
for SQLFORM.grid.
Very thanks Máximo!!
On Tuesday, September 10, 2013 1:44:18 AM UTC+2, [email protected] wrote:
>
> Hi,
>
> I'm using web2py 2.6.0. test.
>
> on sqlhtml.py line 1916:
>
> columns = [f for f in fields if f.tablename in tablenames]
>
>
> when add field count, count not attribute 'tablename' and:
>
> AttributeError: 'Expression' object has no attribute 'tablename'
>
> My code:
> submenus = db.menus.with_alias('menusoptions')
> query = (db.menus.parent_id == 0)
> count = submenus.id.count()
>
> table = SQLFORM.grid(query,
> fields = [
> db.menus.title,
> count,
> ],
> left=submenus.on(db.menus.id ==
> submenus.parent_id),
> groupby=db.menus.title,
> )
> ---
> I think that de problem is field count, this, not have attribute tablename
>
> fiel count is: Expression: COUNT(menusoptions.id)
>
>
> when:
> submenus = db.menus.with_alias('menusoptions')
> query = (db.menus.parent_id == 0)
> count = submenus.id.count()
> menus = db(query).select(db.menus.id,
> count,left=submenus.on(db.menus.id == submenus.parent_id),
> groupby=db.menus.id )
> work fine.
>
>
> Thanks.
>
>
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.