I don't think your model is not setup with the correct reference
fields. Try this:

db.define_table('department',
    Field('dept_id'),
    Field('dept_name'),format='%(name)s')
db.define_table('employee',
    Field('firstName'),
    Field('lastName'),
    Field('dept_id', db.department))

Passing the format parameter to the department table will create the
default validators and represent attributes so that it shows the name
instead of the id.

The dept_id field on the department table seems redundant as the table
will already have an ID field automatically.


On Jun 7, 9:24 am, Jason Lotz <jayl...@gmail.com> wrote:
> Creating a custom crud.read form and I would like to show the
> field.requires=IS_IN_DB field rather than the table.id . Sorry if that
> doesn't make much sense. I have two related tables.
>
> db.define_table('employee', Field('firstName'), Field('lastName'),
> Field('dept_id'))
> db.define_table('department', Field('dept_id'), Field('dept_name'))
> db.employee.dept_id.requires=IS_NULL_OR(IS_IN_DB(db,'department.dept_id','department.dept_name'))
>
> I would like to make a custom form to show the employee name and
> department.
>
> def employee_form():
>   form = crud.read(db.employee, request.args[0])
>   return dict(form=form)
>
> ## View
> {{=form.custom.begin}}
> First Name: {{=form.custom.widget.firstName}}
> Last Name: {{=form.custom.widget.lastName}}
> Department: {{=form.custom.widget.dept_id}}
> {{=form.custom.end}}
>
> This returns the actual dept_id for the Department, but I would like
> to return the dept_name. Is there a better method to accomplish this
> or can some explain custom widgets. I have read the book for custom
> widgets but didn't completely understand it.

Reply via email to