First, I think you want your options table to be linked to your query table 
(i.e., add a reference field referring to the query table).

What you would like to do is probably doable, but I don't think very easily. 
As a simpler alternative, instead of two separate tables, maybe consider a 
single query table that includes a sufficiently larger number of fixed 
options fields. If you will know the number of options needed before the 
form is presented, you can simply hide the extra option fields by setting 
readable=writeable=False for each of them. On the other hand, if the user 
should be allowed to add options dynamically on the client side, then you 
can use jQuery to initially hide some or all of the options and to 
progressively show them as the user requests more options.

Anthony

On Saturday, October 8, 2011 5:43:15 AM UTC-4, faultyzebra wrote:
>
>
> <https://lh6.googleusercontent.com/-Oqkg91ESNIc/TpAaEjPf02I/AAAAAAAAAAU/ox3gqQA4Vwc/poll.png>
> Application: Poll Application
>
> *Database design:*
>
> question body: db.t_query
>
> option body: db.t_option
>
> *model(db_wizard.py):*
>
> ########################################
> db.define_table('t_query',
>     Field('f_content', type='text', requires=IS_NOT_EMPTY(),
>           label=T('Content')),
>     SQLField('is_active',db.auth_user,writable=False,readable=False),
>     auth.signature,
>     migrate=settings.migrate)
>
> db.define_table('t_query_archive',db.t_query,Field('current_record','reference
>  
> t_query',readable=False,writable=False))
>
> ########################################
> db.define_table('t_option',
>     Field('f_ocontent', type='string',
>           label=T('Option')),
>     auth.signature,
>     migrate=settings.migrate)
>
> db.define_table('t_option_archive',db.t_option,Field('current_record','reference
>  
> t_option',readable=False,writable=False))
>
> *controller(default.py):*
> @auth.requires_login()
> def ask():
>     form=SQLFORM.factory(db.t_query,db.t_option,db.t_option)
>     if form.process().accepted:
>         id = db.t_query.insert(**db.t_query._filter_fields(form.vars))
>         form.vars.client=id
>         id = db.option.insert(**db.t_option._filter_fields(form.vars))
>         response.flash='Thanks for filling the form'
>         id = db.option.insert(**db.t_option._filter_fields(form.vars))
>         response.flash='Thanks for filling the form'
>     return dict(form=form)
>
> *view(ask.html)*
> {{extend 'layout.html'}}
>
> <h2>Start a Poll</h2>
> {{=form}}
>
> *Output:*
> See top for screenshot
> Only one instance of db.t_option is seen in the form. How do I get multiple 
> instances of the option field in the form? Is it possible? If not what can I 
> do for a workaround?
>
> Thank you in advance. Also thanks for web2py.
>
>

Reply via email to