Thank you Anthony.
I will need to exclusively modify the variable "status" on other
occasions. So I am not sure I really want "computed fields". Is that
true ?
So I decided to try an onvalidation function and I ended up with :
def status(form):
form.vars.status = [0]*len(form.vars.to)
def write():
form = SQLFORM(db.message)
if form.accepts(request.vars, session, onvalidation=status):
response.flash = 'Got it'
It seems to work.
Is it ok ? If I have understood correctly, onvalidation is called
after validation and before insert. Like this I am sure
"forms.vars.to" does not contain anything fishy or dangerous.
Thanks,
Archibald
On 25 oct, 18:30, Anthony <[email protected]> wrote:
> 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...
>
> Anthony