I just ran into this one. It turns out that the row you want may be inside
the row variable passed, with the table name as its key. How does this
happen? If you have a select that has variables from several tables, for
instance.
I did come up with a workaround, but it's a little, uh... "idiomatic".
lambda row: db.area(row.get('station',row).area_id).name
The clause "get('station',row)" will test the row variable for an embedded
row with the table's name as its key. If no such embedded row is found, it
defaults to returning the rwo variable itself. This has the effect of
trying to look up the table name key and falling back to assuming its just
a simple row.
-- Joe B.
On Tuesday, July 30, 2013 5:35:38 AM UTC-7, Eduardo Cruz wrote:
>
> Hi, I have this table
> db.define_table('station',
> dates,
> Field('name', 'string', unique=True),
> Field('average_time', 'integer'),
> Field('area_id', 'reference area', requires=IS_IN_DB(db, '
> area.id', '%(name)s') ,label="Area", represent=lambda value,row:
> db.area(value).name),
> Field('turn_id', 'reference turn', label="Turno Actual",
> default=1),
> Field("is_active", 'boolean', default=True),
> Field.Virtual('area_name', lambda row:
> db.area(row.station.area_id).name),
> Field('turn_is_hold', compute=lambda row:
> db.turn(row.turn_id).is_hold),
> Field("turn_is_transfer", compute=lambda row:
> db.turn(row.turn_id).is_transfer),
> )
>
>
> And when I try to register an user web2py gives me this error
> <type 'exceptions.AttributeError'> 'Row' object has no attribute 'area_id'
>
>
> If I comment the virtual field it just works but the problem is that I use
> that virtual field in another controller and it works just fine, I dont
> know why I does not works when enter to form to register an user.
> any ideas?
>
>
--
---
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.