Thanks Stifan but also with:
db.products.brand_id_01.requires = IS_IN_DB(db, db.brands.id, '%(name)s')
web2py don't display the "db.brands.name" instead of the 
"db.products.brand_id_01"..

A solution could be make lambda function, what do you think about something 
like that ?
In the controller:
def products_listing():
    query=db.products
    links = [dict(header=T('Brand'), body=lambda row: (something that 
return the brands.name of the products.brand_id_01 current row)]
    fields = 
(db.products.id_01,db.products.code,db.products.description,db.products.brand_id_01)
    grid = SQLFORM.grid(query, fields=fields, links=links)
    return dict(grid=grid)

Is it possible ?

Il giorno domenica 8 dicembre 2013 17:10:18 UTC+1, 黄祥 ha scritto:
>
> i think you should refer it to db.brands.id. e.g.
> db.define_table('brands',
>                 Field('id_01', unique = True),
>                 Field('name'),
>                 format='%(name)s')
> db.define_table('products',
>                 Field('code', unique=True),
>                 Field('description'),
>                 Field('brand_id_01', 'reference brands', requires = 
> IS_IN_DB(db, db.brands.id, '%(name)s')))
>
> it requires the table products to refer to brands id field not id_01 in 
> table brands. not sure what do you want to achieve in here, i think you can 
> make conditional requires.
> e.g. (not tested)
> if 'crm' in request.function :
>     db.products.brand_id_01.requires = IS_IN_DB(db, db.brands.id, 
> '%(id_01)s')
> else:
>     db.products.brand_id_01.requires = IS_IN_DB(db, db.brands.id, 
> '%(name)s')
>
> my point is the reference field in products table is refer to the id field 
> on brands, and for the field represented on drop down list is base on the 
> function, if it contain 'crm' it will show the brands.id_01, other function 
> will show the name.
>
> ref:
>
> http://web2py.com/books/default/chapter/29/07/forms-and-validators#Database-validators
>
> http://web2py.com/books/default/chapter/29/06/the-database-abstraction-layer#Record-representation
>
> best regards,
> stifan
>

-- 
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 web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to