Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get list of field objects in a table in web2py?

Tags:

web2py

How do I get a list of all the field objects (e.g. gluon.dal.Field) in a table? The following

db.customer.fields

just returns a list of strings which are the field names.

like image 888
User Avatar asked Mar 22 '23 20:03

User


2 Answers

field_objects = [f for f in db.customer]
like image 183
Anthony Avatar answered Apr 25 '23 01:04

Anthony


Okay I see that fields are defined as attributes of the table class (gluon.dal.Table). The table class has a __getitem__ method defined which allows indexing by attribute name (as python allows).

Therefore I can get a list of field objects by using a list comprehension:

[db.customer[fieldname] for fieldname in db.customer.fields]
like image 25
User Avatar answered Apr 25 '23 02:04

User