The first argument to IS_IN_DB and IS_NOT_IN_DB can be a Set object rather 
than the entire db:

IS_IN_DB(db(db.courses.teacher = auth.user_id), db.courses.id, '%(title)s 
(%(id)s)')

See http://web2py.com/books/default/chapter/29/7#Database-validators.

Anthony

On Monday, August 13, 2012 8:21:44 AM UTC-4, lucas wrote:
>
> hello one and all,
>
> lets say i have a model like:
>
> db.define_table('courses',
>     Field('user_id', db.auth_user, requires=IS_IN_DB(db, '%s.id' % 
> db.auth_user, '%(last_name)s, %(first_name)s (%(id)s)')),
>     ....
>
> db.define_table('classes',
>     Field('course_id', db.courses, requires=IS_IN_DB(db, db.courses.id, 
> '%(title)s (%(id)s)'), writable=False, readable=False),
>     ....
>
> or, when a teacher is setting up a class, under the classes table, i only 
> want the courses, from the courses table, showing that have his/her 
> user_id, which is known from auth.user_id at the time of login, in the 
> select element of a SQLForm or crud form.
>
> so how do you present only a subset of values for the select element of a 
> form under some kind of boolean test condition?
>
> thanx in advance, lucas
>

-- 



Reply via email to