Solution:
buildrepr=lambda table: lambda id:
SPAN(A(id,_href=URL(r=request,c='default',f='view',vars={'a':table,'i':id})))
for table in a_list:
db.define_table('a_'+table,*[field for field in
db.ipo,db['ipo_'+table]])
db['a_'+table].id.represent=buildrepr(table)
On 12 Αύγ, 20:35, cogarg <[email protected]> wrote:
> Hello,
>
> I'm using a simple loop in my db_custom.py define some some tables
> that contain a combination of fields from other, similarly named
> tables and managed to get it to work.
>
> My question is, is there a way to modify any lambda functions like the
> following two in the example, in order to assign them to the
> db['a_'+table].field.represent inside the loop ?
>
> a_list=['x','y']
>
> db.define_table('ipo',.....)
> db.define_table('ipo_x',.....)
> db.define_table('ipo_y',.....)
>
> for table in a_list:
> db.define_table('a_'+table,*[field for field in
> db.ipo,db['ipo_'+table]])
>
> db.a_x.id.represent=lambda id:
> SPAN(A(id,_href=URL(r=request,c='default',f='view',vars={'a':'x','i':id})))
> db.a_y.id.represent=lambda id:
> SPAN(A(id,_href=URL(r=request,c='default',f='view',vars={'a':'y','i':id})))