On 23 Aug 2012, at 7:48 AM, Anthony <abasta...@gmail.com> wrote:
> db = DAL(lazy_tables=True)
> db.define_table('person',Field('name'),Field('age','integer'),
>    on_define=lambda table: [
>            table.name.set_attributes(requires=IS_NOT_EMPTY(),default=''),
>            
> table.age.set_attributes(requires=IS_INT_IN_RANGE(0,120),default=30),
>   ])
> 
> and the attributes will be set lazily. This is a good idea! Thanks Jonathan.
> 
> Syntax is kind of clunky. How difficult would it be to make lazy Fields so 
> attributes are automatically lazy?
> 

Couple of things (including questions).

1. attributes defined in the Field() spec are lazy already, right? In the above 
example, the attributes could just as well be defined there; my intent was for 
attributes that required more logic, where attributes are being set 
conditionally and it's clumsy to construct different Field() calls to do it.

2. It does not, of course, have to be a lambda expression. My own inclination 
would be to define a separate function.

3. Is there a particular reason to use set_attributes? Why not the more 
readable: table.name.requires = ... ?

-- 



Reply via email to