Hmm, that works for me. Does it work if you do:

db.PhoneNumber.countryTelephoneCode.represent = \
    lambda id, r: '%(countryTelephoneCode)s %(countryName)s' % db.Country(id
).as_dict()

Also, confirm that all values in db.PhoneNumber.countryTelephoneCode do in 
fact reference existing records in the db.Country table. The error you got 
would typically arise if db.Country(id) doesn't return a record.

Finally, consider renaming db.PhoneNumber.countryTelephoneCode to 
db.PhoneNumber.Country or db.PhoneNumber.Country_id -- it actually stores a 
record id from the Country table, not a countryTelephoneCode. The name 
makes the code somewhat confusing to follow.

Anthony

On Wednesday, April 24, 2013 2:48:41 PM UTC-4, Alex Glaros wrote:
>
> That looks like an improvement Anthony but now receive this error
>
> <type 'exceptions.TypeError'> format requires a mapping
>
> There is data in all of the fields (there are no "None" values).
>
> The represent  field names in the above table are as follows:
>
> db.PhoneNumber.countryTelephoneCode.represent = lambda id, r: 
> '%(countryTelephoneCode)s 
> %(countryName)s' % db.Country(id)
>
> any ideas?
>
> thanks,
>
> Alex
>
> On Wednesday, April 24, 2013 10:47:07 AM UTC-7, Anthony wrote:
>>
>> Sorry, try:
>>
>> db.PartyPhoneNumberIntersection.countryTelephoneCode.represent = \
>>     lambda id, r: '%(countryTelephoneCode)s %(countryName)s' % db.Country
>> (id)
>>
>> Anthony
>>
>> On Wednesday, April 24, 2013 1:18:51 PM UTC-4, Alex Glaros wrote:
>>>
>>> Anthony, doesn't there have to be some sort of pointer to the correct 
>>> reference record in the lookup table?
>>>
>>> Here is a real example below (different fields and table than first 
>>> example).
>>>
>>> I tried to put "db.Country" in front of the lookup table field names in 
>>> the "represent" clause, but the syntax is wrong.  Now that you can see the 
>>> lookup table, could you please write out the complete syntax?
>>>
>>> db.define_table('Country', ## Lookup table
>>> Field('countryName','string'), 
>>> Field('countryCode','string'),
>>> Field('countryTelephoneCode','integer'))
>>> ## 
>>> ----------------------------------------------------------------------------------
>>> db.define_table('PhoneNumber',
>>> Field('countryTelephoneCode','reference Country'), 
>>> Field('telephoneNumber','integer'))
>>> ## ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>>> db.PhoneNumber.countryTelephoneCode.represent = lambda v, r: 
>>> '%(db.Country.countryTelephoneCode)s 
>>> %(db.Country.countryName)s' % r
>>>
>>> Thanks,
>>>
>>> Alex
>>>
>>>
>>> On Wednesday, April 24, 2013 5:00:00 AM UTC-7, Anthony wrote:
>>>>
>>>> db.PartyPhoneNumberIntersection.countryTelephoneCode.represent = \
>>>>     lambda v, r: '%(countryTelephoneCode)s %(countryName)s' % r
>>>>
>>>> Anthony
>>>>
>>>> On Wednesday, April 24, 2013 4:08:25 AM UTC-4, Alex Glaros wrote:
>>>>>
>>>>> Is there a way to concatenate fields in the represent function in the 
>>>>> same way that countryTelephoneCode and countryName are in the "requires" 
>>>>> validator below?
>>>>>
>>>>> db.PartyPhoneNumberIntersection.countryTelephoneCode.requires =IS_IN_DB
>>>>> (db, db.Country.countryTelephoneCode, '%(countryTelephoneCode)s %(
>>>>> countryName)s',zero=T('choose one'))
>>>>>
>>>>> thanks,
>>>>>
>>>>> Alex Glaros
>>>>>
>>>>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to