Anthony,
It works. Did not need the ".as_dict()"
The problem was with my data. I still don't know what's wrong with that
table, but tried your statement on a different table with different fields
and it worked.
Thanks for the great tips.
Alex
On Wednesday, April 24, 2013 12:18:35 PM UTC-7, Anthony wrote:
>
> 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 [email protected].
For more options, visit https://groups.google.com/groups/opt_out.