Hi Anthony,
the issue I am pointing to is related to the display of the "owner_id" 
values in the grid itself and
yes, my *real* code sets the "requires" attribute directly in the "thing" 
table definition rather than after the fact as shown above, I didn't think 
that this would make a difference, sorry about that...

On Friday, October 4, 2013 3:31:39 PM UTC+2, Anthony wrote:
>
>
>> db.define_table('gender', Field('name'), format='%(name)s')
>> db.define_table('person', Field('name'), Field('gender_id','reference 
>> gender'), format='%(name)s')
>> db.define_table('thing',  Field('name'), Field('owner_id','reference 
>> person',format='%(name)s')
>>
>> with this controller:
>>
>> @auth.requires_login()
>> def mytest():
>>     grid=SQLFORM.smartgrid(db.thing)
>>     return dict(grid=grid)
>>
>>
>> the owner_id's name is displayed when function above is called, but if I 
>> want to restrict owner_id (to male only for example) with this :
>>
>> db.thing.owner_id.requires=IS_IN_DB(db(db.person.gender_id==db.gender(
>> name='M').id),'person.id')
>>
>> Are you saying the problem is with the display of the "owner_id" values 
> in the grid itself, or in the drop-down in create/edit forms? The above 
> code will not affect the display in the grid, only in drop-downs (unless 
> your *real* code sets the "requires" attribute directly in the "thing" 
> table definition rather than after the fact as shown above).
>
> Assuming the problem is in the dropdown, note that IS_IN_DB takes a 
> "label" argument, which you can set to the _format attribute of the 
> referenced table:
>
> db.thing.owner_id.requires=IS_IN_DB(db(db.person.gender_id==db.gender(name
> ='M').id),
>     'person.id', db.person._format)
>
> Note, if you set the "requires" attribute of the reference field within 
> the table definition itself (i.e., via Field(..., requires=...)), then you 
> will not get the default "represent" attribute, which means the grid itself 
> will only display the id's.
>
> Anthony
>

-- 
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/groups/opt_out.

Reply via email to