I fixed it like this:
    
db.audienceInstances.instances.requires=IS_IN_DB(db(db.instance.type==auth.user.product),'instance.id',lambda
r: '%s %s' %
(db.application[r.app].name,db.server[r.server].hostname),multiple=True)


On Fri, Jul 15, 2011 at 2:52 PM, Nicolas Palumbo <napalu...@gmail.com> wrote:
> Although this is working:
>    
> db.audienceInstances.instances.requires=IS_IN_DB(db(db.instance.type==auth.user.product),'instance.id',multiple=True)
>
> Is only showing ids , disregarding of the format defined here:
>
> db.define_table('instance',Field('app',db.application),Field('server',db.server),Field('type','string'),format=lambda
> r: '%s %s' %(db.application[r.app].name,db.server[r.server].hostname))
>
> IS there any way to fix that?
>
> Thanks,
> Nico
>
> On Thu, Jul 14, 2011 at 1:45 PM, Anthony <abasta...@gmail.com> wrote:
>> The default validator for a list:reference field is
>> IS_IN_DB(db,'<table>.id',multiple=True). Instead of db, you can pass a DAL
>> Set to that validator to filter the returned list -- something like:
>>
>> db.audienceInstances.instances.requires=IS_IN_DB(db(db.instance.type==current_profile.type),'instance.id',multiple=True)
>>
>>
>> See http://web2py.com/book/default/chapter/06#DAL,-Table,-Field and
>> http://web2py.com/book/default/chapter/07#Database-Validators.
>>
>> Anthony
>>
>> On Wednesday, July 13, 2011 2:39:50 PM UTC-4, Nico Palumbo wrote:
>>>
>>> I have currently this multiselect generated by list:references:
>>>
>>> db.py:
>>>
>>>
>>> db.define_table('instance',Field('app',db.application),Field('server',db.server),Field('type','string'),format=lambda
>>> r: '%s %s' %(db.application[r.app].name,db.server[r.server].hostname))
>>> ...
>>> db.define_table('audienceInstances', Field('instances','list:reference
>>> instance'),Field('user',db.auth_user,writable=False, readable=False))
>>>
>>> default.py:
>>>
>>> monitoredInstances = db.audienceInstances(db.audienceInstances.user ==
>>> auth.user.id)
>>>     #Generates a form for the updation of the list of monitored instances
>>>     instancesForm = SQLFORM(db.audienceInstances, monitoredInstances,
>>> submit_button='Update', showid=False)
>>>     if instancesForm.accepts(request.vars, session):
>>>         response.flash = 'list updated'
>>>     elif instancesForm.errors:
>>>         response.flash = 'form has errors'
>>>
>>> That shows a list select among all instances. But what if I'd like to
>>> show a subset of that list, I mean I added a type field in instance
>>> table, and like to get the instances of the type the user has selected
>>> in its profile.
>>>
>>> The only way I can think of is creating a separate audienceInstances
>>> table for each type. Is there any othere way?
>>>
>>> Thanks,
>>> Nico
>>
>

Reply via email to