<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