[web2py] Re: Update on multiple tables with one form

2013-12-27 Thread Matheus Cardoso
I've tried the Anthony's idea and it worked, with one difference, though: 
the id could not be any value. It just worked putting the id with the same 
value of request.arg(0). I think that has some relation with the hidden 
input in custom forms where you have to put the id of the instance that are 
going to be updated. But it worked like a charm. :)

On Tuesday, January 29, 2013 6:24:53 AM UTC-3, AngeloC wrote:

 Hi guys,

 I'm looking for a clean way to make an update on mutiple tables with only 
 one form and cannot find anything clean/simple searching the mailing list.

 Tables could be related (in parent-child relation) or not related at all.

 I'm missing something or there is no easy way to do that?

 Thanks in advance!
  
 -- 
 Profile: http://it.linkedin.com/in/compagnucciangelo 


-- 
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/groups/opt_out.


[web2py] Re: Update on multiple tables with one form

2013-12-26 Thread Matheus Cardoso
Hi guys, sorry about reopen this conversation, but I got stuck in a similar 
situation. My code is almost equal to Annet's code, except that I'm using a 
custom form and I have to pass session=None and formname to form.process(). 
However, I have a field that has to be unique. So, form.process() does not 
accept the validation because the field value is already in db. But, this 
is not the expected behavior for a update form. How can I solve this 
situation?

On Tuesday, January 29, 2013 6:24:53 AM UTC-3, AngeloC wrote:

 Hi guys,

 I'm looking for a clean way to make an update on mutiple tables with only 
 one form and cannot find anything clean/simple searching the mailing list.

 Tables could be related (in parent-child relation) or not related at all.

 I'm missing something or there is no easy way to do that?

 Thanks in advance!
  
 -- 
 Profile: http://it.linkedin.com/in/compagnucciangelo 


-- 
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/groups/opt_out.


[web2py] Re: Update on multiple tables with one form

2013-01-29 Thread Annet
I solved a similar problem the following way:


# retrieve records
node=db(db.node.id==id).select(db.node.ALL).first()
address=db(db.address.nodeID==id).select(db.address.ALL).first()
telecom=db(db.telecom.nodeID==id).select(db.telecom.ALL).first()
# build form
form=SQLFORM.factory(db.node,db.address,db.telecom)
# prepopulate the form
form.vars.field1=node.field1
...
form.vars.field5=address.field5
...
form.vars.field9=telecom.field9
# process form
if form.process().accepted:
node.update_record(**db.node._filter_fields(form.vars)
address.update_record(**db.address._filter_fields(form.vars)
telecom.update_record(**db.telecom._filter_fields(form.vars)


I hope this helps you solve the problem.

Kind regards,

Annet

-- 

--- 
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/groups/opt_out.




Re: [web2py] Re: Update on multiple tables with one form

2013-01-29 Thread Angelo Compagnucci
Hi Annet!

This is freaking awesome and it worked like a charm!

I found a way to add automatically variables to form.vars, hope this helps!

record = db(...).select().first()

for table in [db.table1, db.table2]:
for field in table.fields:
form.vars[field] = record[table][field]


2013/1/29 Annet anneve...@googlemail.com

 I solved a similar problem the following way:


 # retrieve records
 node=db(db.node.id==id).select(db.node.ALL).first()
 address=db(db.address.nodeID==id).select(db.address.ALL).first()
 telecom=db(db.telecom.nodeID==id).select(db.telecom.ALL).first()
 # build form
 form=SQLFORM.factory(db.node,db.address,db.telecom)
 # prepopulate the form
 form.vars.field1=node.field1
 ...
 form.vars.field5=address.field5
 ...
 form.vars.field9=telecom.field9
 # process form
 if form.process().accepted:
 node.update_record(**db.node._filter_fields(form.vars)
 address.update_record(**db.address._filter_fields(form.vars)
 telecom.update_record(**db.telecom._filter_fields(form.vars)


 I hope this helps you solve the problem.

 Kind regards,

 Annet

  --

 ---
 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/groups/opt_out.






-- 
Profile: http://it.linkedin.com/in/compagnucciangelo

-- 

--- 
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/groups/opt_out.




Re: [web2py] Re: Update on multiple tables with one form

2013-01-29 Thread Angelo Compagnucci
To Massimo,

I think this should be in the book after this
http://web2py.com/books/default/chapter/29/07#One-form-for-multiple-tables

Thanks!


2013/1/29 Angelo Compagnucci angelo.compagnu...@gmail.com

 Hi Annet!

 This is freaking awesome and it worked like a charm!

 I found a way to add automatically variables to form.vars, hope this helps!

 record = db(...).select().first()

 for table in [db.table1, db.table2]:
 for field in table.fields:
 form.vars[field] = record[table][field]


 2013/1/29 Annet anneve...@googlemail.com

 I solved a similar problem the following way:


 # retrieve records
 node=db(db.node.id==id).select(db.node.ALL).first()
 address=db(db.address.nodeID==id).select(db.address.ALL).first()
 telecom=db(db.telecom.nodeID==id).select(db.telecom.ALL).first()
 # build form
 form=SQLFORM.factory(db.node,db.address,db.telecom)
 # prepopulate the form
 form.vars.field1=node.field1
 ...
 form.vars.field5=address.field5
 ...
 form.vars.field9=telecom.field9
 # process form
 if form.process().accepted:
 node.update_record(**db.node._filter_fields(form.vars)
 address.update_record(**db.address._filter_fields(form.vars)
 telecom.update_record(**db.telecom._filter_fields(form.vars)


 I hope this helps you solve the problem.

 Kind regards,

 Annet

  --

 ---
 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/groups/opt_out.






 --
 Profile: http://it.linkedin.com/in/compagnucciangelo




-- 
Profile: http://it.linkedin.com/in/compagnucciangelo

-- 

--- 
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/groups/opt_out.




Re: [web2py] Re: Update on multiple tables with one form

2013-01-29 Thread Annet
Hi Angelo,

I am glad you solved your problem.

I found a way to add automatically variables to form.vars, hope this helps!

 record = db(...).select().first()

 for table in [db.table1, db.table2]:
 for field in table.fields:
 form.vars[field] = record[table][field]



I'll give it a try, thanks.

Annet. 

-- 

--- 
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/groups/opt_out.