query = (db.Hotel.chainManager == auth.has_membership('Admin'))
    db.table.field.requires = IS_IN_DB(db(query), db.auth_user.id, 
'%(first_name)s %(last_name)s')


not tested

ref:
http://web2py.com/books/default/chapter/29/07#Database-validators

best regards

On Tuesday, May 7, 2013 8:35:32 PM UTC+7, José Manuel López wrote:
>
> It's not working for me :/ ... still the drop down list contains all the 
> users
>
> On Tuesday, May 7, 2013 1:52:45 PM UTC+2, 黄祥 wrote:
>>
>> yes, you are right, db.auth_user will return all the users table.
>> please try to change 
>> Field('hotel_chain_manager', db.auth_user)
>> into
>> Field('hotel_chain_manager', 'reference auth_user', 
>> default=auth.has_membership('Admin'))
>>
>> hope this can help
>>
>> best regards
>>
>> On Tuesday, May 7, 2013 7:24:05 AM UTC-4, José Manuel López wrote:
>>>
>>>
>>>
>>> Hi!, 
>>> Thank you for your answer, but it's not exactly what I want. 
>>> I'll explain better:
>>> Let's say I have this table:
>>> db.define_table('Hotel',
>>>                 Field('name', label="Nombre del Hotel "),
>>>                                Field('hotel_type', db.BookingCategory),
>>>                 Field('hotel_chain_manager', db.auth_user))
>>>
>>> And now I've a SQLFORM.grid like this:
>>>
>>>
>>>     form = SQLFORM.grid(db.Hotel,
>>>                         searchable=True,
>>>                         deletable=True,
>>>                         details=True,
>>>                         selectable=False, 
>>>                         create=True,
>>>                         sortable=True, 
>>>                         fields=fields, 
>>>                         paginate=100, 
>>>                         maxtextlength=75, 
>>>                         links_in_grid=True)
>>>
>>> as you can see, it is editable, but the Field "hotel_chain_manager" in the 
>>> form will be populated with ALL the users in db. This is not what I want, I 
>>> want that this field will be populated *only with the users in the 
>>> "Admin" membership*.
>>>
>>> Kind Regards!!
>>>
>>> On Tuesday, May 7, 2013 10:36:04 AM UTC+2, 黄祥 wrote:
>>>>
>>>> i think you can achieve it (in controller using grid) with 
>>>> editable = auth.has_membership('Admin')
>>>>
>>>> e.g.
>>>> def booking():
>>>>     has_membership=auth.has_membership('Admin')
>>>>     grid=SQLFORM.grid(db.booking, editable=has_membership)
>>>>     return locals()
>>>>
>>>> best regards
>>>>
>>>> On Tuesday, May 7, 2013 3:16:11 PM UTC+7, José Manuel López wrote:
>>>>>
>>>>> Hi, 
>>>>> I've a " form = SQLFORM.grid " that let the user edit the rows. 
>>>>> In the edit form I want that one of the field populated only with 
>>>>> "Admins". Now I have this field populated with all the db.auth_user and 
>>>>> is 
>>>>> huge and very hard to find the correct user. 
>>>>> How can I do it?, I'm thinking in something like:
>>>>> *db.Hotel.chainManager **=IS_IN_DB( ¿¿??? )*     .... how to express 
>>>>> only users with Admin membership?.
>>>>>
>>>>> Thank you.
>>>>>
>>>>

-- 

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