SQLFORM grid returns a error : query object has no attribute _tablename

272 views
Skip to first unread message

Sarbjit singh

unread,
Jul 16, 2013, 2:03:58 AM7/16/13
to web...@googlegroups.com
I am doing the following steps :

>>> db = DAL('sqlite://storage.db')
>>> db.define_table('person', Field('name'), Field('country'))
>>> db.person.insert(name='John', country='UK')
>>> db.person.insert(name='David', country='US')
>>> query = db.person.name=="David"

>>> SQLFORM.smartgrid(query)

Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "....\gluon\sqlhtml.py", line 2459, in
smartgrid
    if request.args(len(args)) != table._tablename:
AttributeError: 'Query' object has no attribute '_tablename'

While if I try the below code, it works fine.

>>> db(query).select()

Can some one please point me why this query is not working with "smartgrid".

Thanks
Sarbjit


Massimo Di Pierro

unread,
Jul 16, 2013, 6:15:44 AM7/16/13
to web...@googlegroups.com
Answered in other thread...

SQLFORM.grid(query) OK
SQLFORM.smartgrid(table) OK
SQLFORM.smartgrid(query) WRONG!
SQLFORM.smartgrid(table, contraints={'tablename':query}) OK

Ron Chatterjee

unread,
Jan 8, 2016, 2:12:17 PM1/8/16
to web2py-users
Responding to this old post.


    query = db.Project.created_by == auth.user_id;
    
    if_author = lambda row: (row.created_by==auth.user_id)
    #grid = SQLFORM.smartgrid(db.Project, constraints={'db.Project':query},editable=if_author,deletable=if_author,details=True,create=False,csv=False) #doesn't work
    grid = SQLFORM.grid(query,editable=if_author,deletable=if_author,details=True,create=False,csv=False)#works 

why?

Anthony

unread,
Jan 8, 2016, 2:47:56 PM1/8/16
to web2py-users
Instead of {'db.Project': query}, it should be {'Project': query}. db.Project is a Table object, but "Project" is the table name.

Anthony
Reply all
Reply to author
Forward
0 new messages