On Tuesday, October 25, 2011 11:45:41 AM UTC-4, Archibald Linx wrote: > > Thank you Anthony. > > All this works very nicely. > Maybe the default format for auth_user should also be documented. > > Let's say I have the following table : > db.define_table('message', > Field('to', 'list:reference auth_user'), > Field('status', 'list:integer')) > > I want "status" to be a list of 0 as long as "to", but > "db.message.status.default = [0]*len(db.message.to.default)" does not > work. >
db.message.to.default represents the default value for the 'to' field (which you have not set), not the actually values being inserted. Anyway, I don't think the default for one field can reference the values of another. There are a few other options. You could use a computed field (though by default that won't display in a form, if you need that). If inserts/updates will always be handled via form submissions, you could us a form onvalidation function or a custom validator. You could also just do default=[0]*len(request.vars.to), since upon form submission, the values submitted to the 'to' field will be stored in request.vars.to (note, the values stored in request.vars will be the unvalidated values). See here for more details: http://stackoverflow.com/questions/7325776/using-a-lambda-for-a-model-default-in-web2py/7328407#7328407 Anthony