In your controller do something like
def get_name(id):
record = db(db.employees.id==id).select(db.employees.first_name, db.
employees.last_name).first()
return ' %s %s' %(record.first_name, record.last_name)
db.employee.supervisor_id.represent = lambda row: get_name(row.supervisor_id
)
If it's an index list you will get one database hit per row. Better to use
this trick on the edit or view pages.
On Wednesday, November 21, 2012 2:32:54 PM UTC-5, Jim S wrote:
>
> I have a table defined as follows:
>
> employee = db.define_table('employee',
> Field('employeeId', 'id', writable=False, label='Employee #'),
> Field('firstName', length=25, required=True, label='First Name',
> writable=False),
> Field('lastName', length=25, required=True, label='Last Name',
> writable=False),
> ...
> Field('departmentId', db.department, label='Department', writable=False),
> Field('supervisorId', 'reference employee', label='Supervisor', writable=
> False),
> format='%(lastName)s, %(firstName)s')
>
> db.employee.dob.requires = IS_NULL_OR(IS_DATE('%m/%d/%Y'))
> db.employee.seniorityDate.requires = IS_NULL_OR(IS_DATE('%m/%d/%Y'))
> db.employee.hireDate.requires = IS_NULL_OR(IS_DATE('%m/%d/%Y'))
> db.employee.originalHireDate.requires = IS_NULL_OR(IS_DATE('%m/%d/%Y'))
> db.employee.terminationDate.requires = IS_NULL_OR(IS_DATE('%m/%d/%Y'))
>
>
>
>
>
> My supervisorId field displays correctly with the dropdown if it is
> writable, but when I set writable=False it just displays the value of the
> supervisorId field, not the assosiated employee first/last name as the
> format would dictate. departmentId is setup to behave the same way, just
> referencing a different table and it displays the proper 'name' of the
> department when writable=False instead of the id field like supervisorId
> does. Is this a bug?
>
> -Jim
>
--