Thanks Mr. Freeze... I feel dumb after seeing this solution.. I haven't tried this yet, but can already see it working...
On Mar 11, 4:00 am, "mr.freeze" <[email protected]> wrote: > db.define_table('address', > Field('id_client', db.client)) > > if auth.is_logged_in(): > > db.address.id_client.requires=IS_IN_DB(db(auth.accessible_query('read', > db.client)), > 'client.id','% > (name)s') > > On Mar 10, 11:02 am, vihang <[email protected]> wrote: > > > excellent hack... only one problem, it cannot work without logged on > > user, (need user.id) hence it throws an error right away. > > > Any way out ? > > > Traceback (most recent call last): > > File "c:\Users\vihang\Desktop\web2py\gluon\restricted.py", line 173, > > in restricted > > exec ccode in environment > > File "c:/Users/vihang/Desktop/web2py/applications/address/models/ > > db.py", line 77, in <module> > > Field('id_client', db.client, label = 'Client Name', > > requires=IS_IN_DB(db(auth.accessible_query('read', db.client)), > > 'client.id','%(name)s')), > > File "c:\Users\vihang\Desktop\web2py\gluon\tools.py", line 2107, in > > accessible_query > > user_id = self.user.id > > AttributeError: 'NoneType' object has no attribute 'id' > > > On Mar 10, 8:38 pm, mdipierro <[email protected]> wrote: > > > > Field('id_client', db.client, > > > requires=IS_IN_DB(db(auth.accessible_query('read', db.client)), > > > 'client.id','%(name)s')) > > > > On Mar 10, 9:45 am, vihang <[email protected]> wrote: > > > > > say > > > > > db.define('client', > > > > Field('name')) > > > > > db.define('address' > > > > Field('id_client', db.client, requires=IS_IN_DB(db, 'client.id', > > > > '%(name)s')) > > > > > when I use SQLFORM for address table, the input id_client populates > > > > with all names in the client table. I would like it to populate with > > > > only those names where are authorized. The output would be equivalent > > > > to db(auth.accessible_query('read', db.client)).select(db.client.id, > > > > db.client.name) > > > > > Does it make sense? > > > > > On Mar 10, 7:37 pm, mdipierro <[email protected]> wrote: > > > > > > I believe you do not need a new validator you can just use IS_IN_DB > > > > > but can you give us more details? > > > > > > On Mar 10, 9:18 am, vihang <[email protected]> wrote: > > > > > > > Hello, > > > > > > > I am trying to write a validator which I can use to populate select > > > > > > box using result from auth.accessible_query. I believe IS_IN_DB > > > > > > validator would be a good start. Could some give me a hint if there > > > > > > is > > > > > > an easy tweak I can apply, or will it be dirty hack? > > > > > > > Thanks > > > > > > vihang -- You received this message because you are subscribed to the Google Groups "web2py-users" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/web2py?hl=en.

