On Tue, Aug 23, 2011 at 11:18 PM, DenesL <denes1...@yahoo.ca> wrote:

>
> Thanks pbreit, but they are not virtual fields, they are just based on
> another field definition.
>
> Maybe with a function:
>
> def like(field, name):
>  import copy
>  f = copy.copy(field)
>  f.name = name
>  f.label = ' '.join(x..capitalize() for x in name.split('_'))
>  return f
>
> name = Field('name','string',length=20,requires=IS_NOT_EMPTY())
> db.define_table('person',
>  like(name, 'firstname'),
>  like(name, 'lastname'),
>  Field('age', 'integer'),
>  ...
>
>
Very usefull, I think it need to be included in web2py, maybe in DAL.Field
as a static method.

something like

# define field templates
fieldtemplate = dict(
    text = Field('name','text',requires=IS_NOT_EMPTY(), represent=...),
    integer = Field('name','integer',.....)
)

# define tables
db.define_table('somthing',
        Field('x'),
        Field.template(text,'myfieldname')
)

Your like function go in Field.template static_method

Reply via email to