On Mon, May 22, 2017 at 4:35 PM, 'Annet' via web2py-users < web2py@googlegroups.com> wrote:
> I have the following query and form: > > user = db.auth_user(vertexID=vertexID) > > form = SQLFORM.factory(db.auth_user, db.auth_dummy, > extra_fields=extra_fields) > > If the form validates I want to update user with data I selected from > other tables and > with data from the form. I have the following code; > > user.update_record(field1=value1, field2=value2) > user.update_record(**db.auth_user._filter_fields(form.vars)) > > I wonder whteher there is a more elegant solution than calling > user.update_record() twice > > Yes. From the book: "However, if you assign a value to form.vars.field, this value *will* be part of the insert or update when the form is processed. " form.vars is a gluon.storage.Storage object ... so you can use it (see: http://web2py.readthedocs.io/en/latest/storage.html?highlight=gluon.storage.Storage). Just do: form.vars.field1 = value1 form.vars.field2 = value2 user.update_record(**db.auth_user._filter_fields(form.vars)) Miguel -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- 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 web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.