Oh, and to get rid of the empty choice at the top of the list, add 
zero=None:
 
IS_IN_DB(..., zero=None)
 

On Wednesday, July 13, 2011 9:22:50 PM UTC-4, Anthony wrote:

> For reference, see 
> http://web2py.com/book/default/chapter/07#Database-Validators.
>  
>
> On Wednesday, July 13, 2011 9:21:54 PM UTC-4, Anthony wrote:
>
>> IS_IN_DB takes a DAL set, so you can limit the records returned. If you 
>> want the record ID returned, use db.setup.id. So, maybe something like 
>> this:
>>  
>> Field('setup', requires=IS_IN_DB(db(db.setup.ready==True), db.setup.id, 
>> '%(setupname)s'))
>>  
>>  
>> Anthony
>>
>> On Wednesday, July 13, 2011 9:06:03 PM UTC-4, Gwayne aka Mike Veltman 
>> wrote:
>>
>>> This will probably a facepalm moment but I can not figure it out. 
>>>
>>> My present used form function 
>>>
>>>     form = SQLFORM.factory(
>>>     Field('setup', requires=IS_IN_DB(db, db.setup.setupname, 
>>> '%(setupname)s')
>>>     ))
>>>     
>>>
>>> Model 
>>>
>>> db.define_table('setup', 
>>>
>>>     Field('setupname', type='string',
>>>           unique=True,
>>>           label=T('Setup name')),
>>>     Field('description', type='string',
>>>           label=T('Description')),
>>>     Field('frame_id', db.frame,
>>>           label=T('Frame ID')),
>>>     Field('course_id', db.course,
>>>           label=T('Course ID')),
>>>     Field('ready', type='boolean',
>>>           default=False,
>>>           label=T('Ready for use')), 
>>>     Field('nostorage', type='boolean',
>>>           default=False,
>>>           label=T('No storage needed')),
>>>     Field('noprofiles', type='boolean',
>>>           default=False,
>>>           label=T('No profiles needed')),
>>>     Field('nonim', type='boolean',
>>>           default=False,
>>>           label=T('No nim actions needed')),
>>>       Field('securitylevel', type='integer',
>>>           default=0,
>>>           label=T('Security Level')),
>>>     Field('created_on','datetime',default=request.now,
>>>           label=T('Created On'),writable=False,readable=False),
>>>     Field('modified_on','datetime',default=request.now,
>>>           label=T('Modified On'),writable=False,readable=False,
>>>           update=request.now),
>>>     format='%(setupname)s',
>>>     migrate=settings.migrate)   
>>>
>>> What I try to get is that the form only shows the setupname of the 
>>> records 
>>> where setup.read==True and then returns setup.id so I can use that. 
>>>
>>> A addtional would be that the first selection is the first record and not 
>>>
>>> empty. 
>>>
>>> Thanks in advance. 
>>>
>>>
>>> With regards,
>>> Mike Veltman 
>>>
>>>
>>>              

Reply via email to