Field('dungeon', 'reference dungeons', required=True, notnull=True,
      represent=lambda v, r: '(%s %s) %s' % (r.dungeon.mountain.x,
          r.dungeon.mountain.y, r.dungeon.pos))

This may also work:

db.define_table('dungeons',
    ...
    format=lambda r: '(%s %s) %s' % (r.mountain.x, r.mountain.y, r.pos))

Careful, though -- these involve separate recursive selects for every 
record, so not efficient if displaying a large number of records (in that 
case, better to do an explicit join to get the values you want to display).

Anthony

On Sunday, March 31, 2013 10:50:46 AM UTC-4, Vladimir Kaznacheev wrote:
>
> ok. may i get representation for *mountain *to be used 
> in representation for *dungeons*?
>
> воскресенье, 31 марта 2013 г., 18:39:29 UTC+4 пользователь Anthony написал:
>>
>> format='(%(mountain.x)s %(mountain.y)s) %(pos)s'
>>
>> If "format" is a string, it can only include the names of fields within 
>> the current table (e.g., "mountain").
>>
>> Anthony
>>
>> On Sunday, March 31, 2013 9:48:47 AM UTC-4, Vladimir Kaznacheev wrote:
>>>
>>>
>>> in *db.py*
>>> db.define_table('mountains',
>>>     Field('m_id','integer', required=True),
>>>     Field('pos','integer'),
>>>     Field('x','integer'),
>>>     Field('y','integer'),
>>>     format='(%(x)s %(y)s)',
>>> )
>>>
>>> db.define_table('dungeons',
>>>     Field('d_id','integer', required=True),
>>>     Field('mountain', 'reference mountains', notnull=True), 
>>>     Field('pos','integer'),
>>>     format='(%(mountain.x)s %(mountain.y)s) %(pos)s',
>>> )
>>>
>>> db.define_table('dungeon_resources',
>>>     Field('dungeon', 'reference dungeons', required=True, notnull=True),
>>>     Field('mine', 'string'),
>>>     Field('quantity', 'integer'),
>>> )
>>>
>>>
>>> in *controllers/default.py*
>>> def ResourceMap():
>>>     form = SQLFORM.grid(db.dungeon_resources, searchable=True, 
>>> create=False, editable=False, deletable=False, details=False)
>>>     return dict(form=form)
>>>
>>> when i try open *http://<app>/default/ResourceMap* i get error ticket
>>> <type 'exceptions.AttributeError'> 'Table' object has no attribute 
>>> 'mountain.x'
>>>
>>> without *format* in *db.define_table* table displays, but it is not 
>>> informative
>>>
>>

-- 

--- 
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.


Reply via email to