Got error when I put 'fields' as an argument to SQLFORM.grid

113 views
Skip to first unread message

at

unread,
Jan 26, 2021, 5:45:49 AM1/26/21
to web2py-users
Here is the code:
`fields=['id', 'name']`
`grid = SQLFORM.grid(db.engagement, fields=fields)`

Error:
`AttributeError('str' object has no attribute 'tablename')`


Jim S

unread,
Jan 26, 2021, 4:50:01 PM1/26/21
to web2py-users
Can you try with the field in the format:

db.tablename.fieldname

ex:


-Jim

Muhammad Atif Ayaz

unread,
Jan 27, 2021, 4:45:45 AM1/27/21
to web...@googlegroups.com
Thank you Jim, it works.

Do you think a way that can help dynamically making a list of all fields of a table and then we can remove specific fields from it.
Like the following which produces the required list but in the desired data-type:
fields = [fld for fld in db.engagement.fields if fld!='token']
grid = SQLFORM.grid(db.engagement, fields=fields)


--
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 a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/Ym3zsLYNePg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/web2py/e19daf19-95c7-4e46-88da-74882bd4e51an%40googlegroups.com.

Jim Steil

unread,
Jan 27, 2021, 1:30:43 PM1/27/21
to web...@googlegroups.com
What is wrong with using the example you provided?

-Jim


Muhammad Atif Ayaz

unread,
Jan 28, 2021, 4:31:04 AM1/28/21
to web...@googlegroups.com
It gives error: `AttributeError('str' object has no attribute 'tablename')`

The reason is that the field names are in string format not in db.tablename.fieldname format


valq...@gmail.com

unread,
Jan 29, 2021, 4:14:38 AM1/29/21
to web2py-users
db.table['fieldname']


четверг, 28 января 2021 г. в 07:31:04 UTC+3, at:

Muhammad Atif Ayaz

unread,
Jan 30, 2021, 6:13:45 AM1/30/21
to web...@googlegroups.com
Thank you very much!

Reply all
Reply to author
Forward
0 new messages