Note, the default IS_IN_DB validator for a reference field also sets the 
label argument of the validator to be the _format attribute of the 
referenced table (so the select will show a more descriptive field or set 
of fields from the referenced table rather than just the record number). If 
you're overriding the default validator, you'll need to explicitly specify 
the label argument as well. Assuming the reference is to the auth_user 
table, something like:

db.table.field.requires = IS_IN_DB(db(query), 'auth_user.id', 
db.auth_user._format)

If you don't like the default auth_user format, you can specify a custom 
format (e.g., '%(last_name)s, %(first_name)s').

Anthony

On Wednesday, May 30, 2012 6:41:58 PM UTC-4, Rod Watkins wrote:
>
> RTM, eh. I didn't think to look at the IS_IN_DB validator for this. In 
> fact, I didn't even have one as I was relying on the default. Thanks!!
>
> On Wednesday, 30 May 2012 13:55:35 UTC-7, Niphlod wrote:
>>
>> IS_IN_DB takes also a queryset .....
>> Directly from http://web2py.com/books/default/chapter/29/7
>>
>> query = (db.table.field == 'xyz') #in practice 'xyz' would be a variable
>> db.table.field.requires=IS_IN_DB(db(query),....)
>>
>>
>> put that before calling SQLFORM and voilĂ .
>>
>>
>> Il giorno mercoledì 30 maggio 2012 22:47:33 UTC+2, Rod Watkins ha scritto:
>>>
>>> Hello everyone,
>>>
>>> I have a quick question.
>>>
>>> I am using the SQLFORM tool and creating a form using the generated 
>>> custom widgets. One part of the form allows a one to choose a user from a 
>>> select list (the table has a reference to auth_user). I'd like to limit the 
>>> options shown in the select list to only those users who are a member  of a 
>>> specific group. Is there a way to apply a filter to restrict the users 
>>> added to the select widget?? 
>>>
>>> Rod
>>>
>>

Reply via email to