In the controller:

db.trip_instance.trip_type.default=<computed value>

mic


2011/9/7 Ray (a.k.a. Iceberg) <[email protected]>:
> On Sep 7, 3:00 am, Lennon <[email protected]> wrote:
>> I'm try to use a lambda to set a default value based on a value in
>> another table.  Here is my model:
>>
>> db.define_table('trip_instance', timestamp, sos_table,
>>     Field('trip_type_id',  db.trip_type, label='Trip Type',
>> widget=trip_select_widget, requires = IS_IN_DB(db, 'trip_type.id', '%
>> (name)s'), represent=lambda id:db.trip_type(id)['name']),
>>     Field('total_slots', 'integer', default=lambda r:
>> db.trip_type(r.trip_type_id)['total_slots']),
>>
>> Locally this causes an error that says:
>>
>> TypeError: <lambda>() takes exactly 1 argument (0 given)
>>
>> And on my server (Linode) there is no error but when I try and create
>> a new trip instance with sqlform the total slots field is pre-
>> populated with this:
>>
>> <function <lambda> at 0x7f27684b7140>
>>
>> My lambda looks almost identical to the one that works fine for
>> represent in the trip_type_id field except I'm using the table instead
>> of the field.  Is that what I'm doing wrong?
>
>
> Looks like the default parameter does not want a lambda. Try to give
> it a computed value instead.
>
> Regards,
> Ray

Reply via email to