represent is a lambda function binded to a Row object, look into row with
shell it help to better understand.

Richard

On Tue, Feb 14, 2012 at 4:07 PM, monotasker <[email protected]> wrote:

> OK, I'm trying to create a generic controller function that will list the
> rows in a table, representing each row using a flexible format that can be
> user-defined (this is all for a plugin to provide a list-and-edit-records
> widget).
>
> My testing model includes this table definition:
>
> db.define_table('npcs',
>     Field('name', 'string'),
>     Field('location', 'list:reference db.locations'),
>     Field('image', 'upload', uploadfolder = os.path.join(request.folder,
> "static/images")),
>     Field('notes', 'text'),
>     format = '%(name)s')
> db.npcs.id.represent = lambda id, row: row.name
> db.npcs.location.requires = IS_IN_DB(db, 'locations.id',
> db.locations._format, multiple = True)
> db.npcs.location.widget = lambda field, value: AjaxSelect(field, value,
> 'locations', multi = 'basic').widget()
>
> My controller then does a select() on the table and loops through the rows
> (as rowlist):
>
> listset = []
> for r in rowlist:
>         listformat = r.id.represent
>         listset.append(listformat)
>
> At present this code generates an error saying that the int object "id"
> doesn't have a property 'represent'. I've just re-read the book on the
> represent property and it actually says very little about its
> implementation. I also can't find any explanation of how to pass a row to
> the _format property. So help with either/both would be much appreciated.
>
> Thanks,
>
> Ian
>

Reply via email to