Dear Everyone,

I am still plugging away on web2py and loving it more and more the
better I understand python.

I have a page where a large list is generated from a database query.
Next to each item from the list, I would like to put the ability to
add a comment.

I did this statically by creating X number of forms for X number of
list items displayed on the page, so I know the concept is possible.
Now, I want to make it dynamic.  I searched this group, and all over
the web for "dynamic form web2py", "multiple form web2py", etc. and
all iterations thereof.

I did find these threads:
http://groups.google.com/group/web2py/browse_thread/thread/1f577d46bd535433
https://groups.google.com/forum/#!topic/web2py/nE_-yhDG-3o

The second one seemed closer to what I'm trying to do, but for now, my
problem is much simpler.  I have one table, one query, and just a
variable number of fields.  I tried every syntax I could muster
blindly trying to pass in a list of fields to SQLFORM or
SQLFORM.factory.

Below is my code, chopped of the unimportant bits for clarity:

def multi_comment():
    records=db(myquery).select()
    fields=[]
    counter=1
    for i in records:
        fields.append(Field('note','text'))
        fields.append(Field('div_id', default=str(counter)))
        counter=counter+1
    pass
    form=SQLFORM.factory(*fields)
    return dict(form=form, fields=fields)

I am getting only one field in my form with a div_id of 1.  I know
there has to be a simple way to do this, I am just not skilled enough
to do it.

Any suggestions?  Also, any help with implementing the db insert after
the form has been processed would be wonderful!

Thank you in advance!

Reply via email to