Hi, I'm using a custom form to represent the fields of a table. This table has referenced fields.
If I use:
db.define_table('department',
Field('dept_id'),
Field('nombre'),format='%(nombre)s')Field('dept_id', db.department))
db.define_table('employee',
Field('firstName'),
Field('lastName'),
The table employee represents correctly the dept names. But if I do:db.define_table('employee',Field('dept_id', db.department), requires=IS_EMPTY_OR(IS_IN_DB(db, db.department.id,
Field('firstName'),
Field('lastName'),
'%(nombre)s')))
Field('dept_id', db.department, requires=IS_EMPTY_OR(IS_IN_DB(db, db.department.id,
'%(nombre)s'))))
{{=form.custom.widget.dept_id}} shows the departament id instead of the name.
I need to add the "IS_EMPTY_OR" condition, I've also tried adding notnull=False without success.
On Tuesday, August 26, 2014 3:13:35 PM UTC-4, José L. wrote:Hi, I'm using a custom form to represent the fields of a table. This table has referenced fields.
If I use:
db.define_table('department',
Field('dept_id'),
Field('nombre'),format='%(nombre)s')Field('dept_id', db.department))
db.define_table('employee',
Field('firstName'),
Field('lastName'),
The table employee represents correctly the dept names. But if I do:db.define_table('employee',Field('dept_id', db.department), requires=IS_EMPTY_OR(IS_IN_DB(db, db.department.id,
Field('firstName'),
Field('lastName'),
'%(nombre)s')))
I assume the above is a typo -- should be:
Field('dept_id', db.department, requires=IS_EMPTY_OR(IS_IN_DB(db, db.department.id,
'%(nombre)s'))))
{{=form.custom.widget.dept_id}} shows the departament id instead of the name.
I need to add the "IS_EMPTY_OR" condition, I've also tried adding notnull=False without success.
Are you saying that in a create or update form, the select dropdown includes a list of IDs rather than names, or that in a grid or read-only form you see IDs rather than names? The former should not be the case, and when I try it, I see a list of names. If the latter is the problem, that is because you have not defined a "represent" attribute for the dept_id field (if you explicitly specify a "requires" argument when defining a reference field, you do not get the automatic "represent" attribute defined, so you have to define that explicitly as well).
Anthony
represent = lambda id, row: db.department._format % db.department(id)