4

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.

User
  • 62,498
  • 72
  • 186
  • 247

2 Answers2

6
field_objects = [f for f in db.customer]
Anthony
  • 25,466
  • 3
  • 28
  • 57
1

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]
User
  • 62,498
  • 72
  • 186
  • 247