On Saturday, April 9, 2011 7:34:25 AM UTC-4, Serbitar wrote:
>
> Sorry, misstyped and sent the message early. So once again:
>
> I can create database fields from a list like this:
>
> list = ["a","b","c","d"]
> fields = []
> for entry in list:
> fields += [Field(entry, type="string")]
> db.define_table('test', *fields)
>
> Now I want to have a virtual field for each field in the list.
> Any way to do this? As virtual field names are not strings but
> function names I got no idea how to do this.
To create virtual fields, you first have to define a class, such as:
class MyVirtualFields(object):
Then you need to add a function (method) for each virtual field, which
presumably you could do dynamically. However, the virtual field functions
have to compute something in order to return virtual field values -- how
would you define what each virtual field does dynamically? Can you provide
more detail regarding what each of the virtual fields would return?
Anthony