OK, then maybe:
admin_users = db(db.auth_membership.group_id == auth.id_group('Admin'))\
.select(db.auth_membership.user_id, projection=True)
...
requires=IS_IN_DB(db(db.auth_user.id.belongs([r.id for r in admin_users])),
...)
I think GAE may limit the .belongs() to only 30 items, though, so if it
might contain more, you may need to build the list separately and use an
IS_IN_SET() validator instead. Others with GAE experience may have better
ideas.
Anthony
On Tuesday, May 7, 2013 9:55:37 AM UTC-4, José Manuel López wrote:
>
> Thank you Anthony for your help,
> The problem now is this:
> <type 'exceptions.RuntimeError'> Too many tables selected
> Can be a problem that I'm over GAE?
>
> On Tuesday, May 7, 2013 3:43:32 PM UTC+2, Anthony 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'))
>>>
>>
>> He wants to limit the options shown in the dropdown, not set a single
>> default value (also, auth.has_membership() returns True/False, not a user
>> ID).
>>
>> When you specify a reference field, you get a default IS_IN_DB validator,
>> but you can explicitly define your own, which enables you to specify a Set
>> object as the first argument to limit the records displayed (see
>> http://web2py.com/books/default/chapter/29/07#Database-validators):
>>
>> Field('hotel_chain_manager', 'reference auth_user',
>> requires=IS_IN_DB(db((db.auth_user.id == db.auth_membership.user_id
>> ) &
>> (db.auth_group.id == db.auth_membership.
>> group_id) &
>> (db.auth_group.role == 'Admin')),
>> 'auth_user.id', db.auth_user._format),
>> represent=lambda id, row: db.auth_user._format % row)
>>
>> Note, when you explicitly specify the "requires" of a reference field,
>> you lose the default "represent" attribute, so you have to add that
>> explicitly as well.
>>
>> Anthony
>>
>>>
--
---
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.