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.
field_objects = [f for f in db.customer]
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]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With