Hello Massimo,

I will try to make myself clear...

My objective is to manage the insertion of an arbitrary number of records in
a second table with a normalised "one to many" relation between 2 tables.

I had this Idea :

I would make a form and use the virtual field to get the number of rows to
insert in the second table. Then create the rows and send a refreshing order
to the component of the second table embeded into the same page that could
use the example you sent to manage the insertion of the many record into the
second table...

It seems a good way to resolve the issue of insertion a arbitrary number of
record in a normalized relation of 2 table.

The only thing I would need is a way to trigger the insertion and refresh of
the component without the user to having to clic submit before the rows are
created in the second table (jQuery would surely be required for this).

For example if I have this model :

db.define_table('tab1',
    Field('hose_description_or_address','string'),
    Field('number_of_room','integer'))

db.define_table('tab2',
    Field('room_number','integer'),
    Field('room_description','string'),
    Field('tab1_id',db.tab1))


So I would like that when inserting a value in "number_of_room" field into
tab1 form that there is a trigger event that create those rows into the tab2
and send refresh order to the component of tab2 so the embeded component
will automatically showed the 2 rows that allow the user to insert the
details requires to finalize the insertion of the records.

I didn't try anything for now, I see many difficulties like having to have a
update mode form for the component with empty rows... With crud this should
turn in a create mode form since there will have no record id passed.

Other problem that I see is if the user have already start to fill the
second table rows then he decide he made a mistake (only 2 rooms instead of
3). The refresh order sent to component will clear his already inserted
value... I could use keepvalues but it will be difficult to keeps the right
values in case the user is removing a rows... Adding a + or - button beside
the row of the second table component will required a callback to the form
of tab1 to set accordingly the "number of room field"...


What do you think?

Do you see other workflow problem in this solution?

Thanks

Richard

On Sun, Sep 11, 2011 at 10:51 PM, Massimo Di Pierro <
massimo.dipie...@gmail.com> wrote:

>
> rows = db(yourquery).select(mytable.id, mytable.myfield)
> form = SQLFORM.factory(*[Field('name_%s'%r.id, default=r.myfield) for
> r in rows])
> if form.process().accepted:
>    for key,value in form.vars.items():
>        db(mytable.id==key[5:]).update(myfield = value)
>
> form.process().accepted is the same as form.accepted(request,session)
> but shorter.
>
> On Sep 10, 2:55 pm, Serbitar <rserbi...@googlemail.com> wrote:
> > is there any way to update multiple records with crud.update, or even
> > records with a given query?
>

Reply via email to