In db.py:

db.define_table('job',
                        Field('filename', 'string', label='File Name',
requires = IS_NOT_EMPTY()),
                        Field('total_duration_minutes', 'integer',
label ='Total Duration (minutes)', requires = IS_NOT_EMPTY()))

db.define_table('worker', Field('filename', 'string', requires =
IS_IN_DB(db, 'job.filename'), Field('name','string',
requires=IS_NOT_EMPTY())))

Every job may be assigned to multiple workers (one-many relationship).

Controller (default.py) code:

def assign():
    """
    assign a newly created job to workers <br/>
    """
    jobform = SQLFORM(db.job, request.args[0], readonly = True) #
request.args[0] is the id of the current job

    # fetch existing workers
    records = db((db.worker.filename == request.args[1])).select()

    # add the above to the read-only form
    for r in range(len(records)):
        readonlyrecord = TR(TD(str(r+1)), TD(records[r].name), TD
(records[r].filename))
        jobform[0].append(readonlyrecord)

    # add an additional row to the form for assigning transcribers
    form = SQLFORM(db.worker, keepopts=['filename'])
    newrow = TR(TD(''),SELECT(form.custom.inpval.filename,
name='filename'), \
    INPUT(_type='text',name='name', requires=IS_NOT_EMPTY()), INPUT
(_type='submit', _value='Add another'))
    jobform[0].append(newrow)

    if form.accepts(request.vars, session):
        session.flash = 'Added worker!'
        db.worker.insert(job_id = request.args[0], name =
jobform.vars.name) # control never reaches here
        redirect(URL(r=request, f='assign', args=request.args))
    elif form.errors:
        session.flash = 'Some error occured.'

    return dict(jobform = jobform)

There may be some typos, please use your judgement to correct them. :)

On Jan 25, 6:52 pm, mdipierro <mdipie...@cs.depaul.edu> wrote:
> I need to try this. Can you post the entire action and a sample (one
> field) child and parent tables?
>
> On Jan 25, 5:36 am, Adi <aditya.sa...@gmail.com> wrote:
>
>
>
> > Corrections: form1 = SQLFORM(db.parent, record, readonly=True)
>
> > On Jan 25, 4:35 pm, Adi <aditya.sa...@gmail.com> wrote:
>
> > > Hi all,
>
> > > I'm trying to build a custom form in this fashion:
>
> > > There's a parent table and a child table (many one relationship). I've
> > > created a read-only SQLFORM for a record of the parent, and then I'm
> > > trying this:
>
> > > form1 = SQLFORM(db.parent, readonly=True)
>
> > > form2 = SQLFORM(db.child, keepopts=['gender'])
>
> > > form1[0].append(TR(INPUT(_type='text', name='name',
> > > requires=IS_NOT_EMPTY()), \
> > > SELECT(form2.custom.inpval.gender, name='gender'),\
> > > INPUT(_type='submit', _value='Add another'))
>
> > > This gives me the appearance of the form as I want, i.e., parent read-
> > > only record in a form, with additional single row of updateable child
> > > form with "Add another" button. The second form is to provide a drop-
> > > down list for 'gender'. However, in this case the "Add another" button
> > > doesn't submit, i.e, I can't get control in form1.accepts or
> > > form2.accepts.
>
> > > What am I doing wrong?

-- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To post to this group, send email to web...@googlegroups.com.
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en.

Reply via email to