Have a Model as follows:

from gluon.tools import Auth
auth=Auth(db)
auth.define_tables()
db.define_table('person',Field('name'),format='%(name)s')
db.define_table('dog',Field('name'),Field('owner',db.person))
db.dog.owner.requires = IS_IN_DB(db, 'person.id', db.person._format)

and a controller:

def index():
  db.dog.id.readable=False
  fields = (db.dog.id, db.dog.name, db.dog.owner)
  table = SQLFORM.grid(db.dog, fields)
  return dict(table=table)

Main issue:
the grid returns the id rather than the name for the owner.
Edit and view both return the name (as expected).
Is there a problem with the model/ controller syntax?

Side issue:
In the controller, fields line, if db.dog.id is left out, the grid
returns an id ticket error.

Traceback (most recent call last):
  File "gluon/restricted.py", line 194, in restricted
  File "C:/web2py/applications/pt2/controllers/dogs.py", line 7, in
<module>
  File "gluon/globals.py", line 145, in <lambda>
  File "C:/web2py/applications/pt2/controllers/dogs.py", line 4, in
index
  File "gluon/sqlhtml.py", line 1647, in grid
  File "gluon/dal.py", line 3835, in __getitem__
KeyError: 'id'

This occurs with or without the second line (... readable=False)
commented out.
Wanted to show the id in edit and view forms but not in the grid.
Can this be achieved?

Reply via email to