I'm trying to improve ch 6 in the book, DAL. 
The on_define parameter to define_table is not documented. 

This is my current text, but the example concerns me because it seems 
redundant to me. That is, until I found the example, I thought that adding 
such simple requires settings via Field definitions would still leave the 
table lazily defined.  

on_define

on_define is a callback triggered when a lazy_table is instantiated, 
although it is called anyway if the table is not lazy. This allows dynamic 
changes to the table without losing the advantages of delayed instantiation.

Example:

 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), 




-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to