You have to remove the entire "requires" attribute. Try defining the health 
table after the types and tabs tables:

db.define_table('types',
    Field('name','string',length=255,requires=IS_NOT_EMPTY()),
    Field('description','text',requires=IS_NOT_EMPTY()),
    format='%(name)s (%(description)s)')

db.define_table('tabs',
    Field('name','string',length=255,requires=IS_NOT_EMPTY()),
    Field('description','text',requires=IS_NOT_EMPTY()),
    format='%(name)s')

db.define_table('health',
    Field('type_id', db.types),
    Field('time_min', 'string', length=255, requires=IS_NOT_EMPTY()),
    Field('time_max', 'string', length=255),
    Field('tab_id', db.tabs)

Anthony

On Wednesday, August 1, 2012 1:12:12 PM UTC-4, lyn2py wrote:
>
> I'm trying to understand...
>
> Do you mean that if I leave out the validator, i.e. make it
>
> requires=IS_IN_DB(db,'sometable.id')
>
> or do you mean to remove the whole "requires" attribute?
>
> Yes, they are exactly the same (the format attributes in table and in the 
> reference), and I don't wish to repeat them either, but how do I get the 
> drop down menus with the correct formatting?
>
> I have tried different combinations but the correct referencing with drop 
> down menus still doesn't work. These are my tables, please kindly help.
>
> db.define_table('health',
>     Field('type_id','reference types',requires=IS_IN_DB(db,'types.id',
> '%(name)s (%(description)s)
> ') ),
>     Field('time_min','string',length=255,requires=IS_NOT_EMPTY()),
>     Field('time_max', 'string',length=255),
>     Field('tab_id','reference tabs',requires=IS_IN_DB(db,'tabs.id',
> '%(name)s') ),
> )
>
>
> db.define_table('types',
>     Field('name','string',length=255,requires=IS_NOT_EMPTY()),
>     Field('description','text',requires=IS_NOT_EMPTY()),
>     format='%(name)s (%(description)s)'
> )
>
>
> db.define_table('tabs',
>     Field('name','string',length=255,requires=IS_NOT_EMPTY()),
>     Field('description','text',requires=IS_NOT_EMPTY()),
>     format='%(name)s'
> )
>
> I would like to have the drop down menu available for choosing AND for the 
> correct format for referencing when listing the items. Am I writing the 
> wrong code?
>
> I have tried:
>
>    - removing the "format" attribute in the "requires=" attribute
>       - drop down menus available but the format is the ID 
>    
>
>    - removing the entire "requires" attribute
>       - no drop down menus
>    
> The "represent" solution works, but I was wondering if there was a way 
> about it, since the web2py manual says so and if I understand your reply 
> correctly, I'm probably doing it wrong somewhere.
>
> I have many references, so there will be lambdas all over the place. Not 
> very DRY... Can I learn the correct method to achieve this please?
>
> Thank you!
>
> On Thursday, August 2, 2012 12:18:54 AM UTC+8, Anthony wrote:
>>
>> Do you mean like:
>>>
>>> requires=IS_IN_DB(db,'sometable.id','%(name)s (%(description)s)')
>>>
>>> If so, yes I have them there. The purpose is to create the drop down 
>>> menu... unless I'm doing it wrong? Or is there another way about it so that 
>>> the references will appear per the manual?
>>>
>>
>> Yes, that's what I mean. By specifying the validator, you no longer get 
>> the default "represent" attribute. Is '%(name)s (%(description)s)' the 
>> same as the "format" attribute of the db.sometable table? If so, there's no 
>> reason to explicitly specify that validator, as you will get exactly that 
>> validator by default anyway (in which case, you will also get the default 
>> "represent" attribute).
>>
>> Alternatively, you can do:
>>
>> Field('sometable', db.sometable, requires=IS_IN_DB(...),
>>     represent=lambda id, row: db.sometable._format % db.sometable(id))
>>
>> Anthony
>>
>

-- 



Reply via email to