Sorry, wasn't thinking -- the validator is selecting a record from the
"room" table, not the "booking" table, so you'll need a slightly different
function for that:
IS_IN_DB(..., label=lambda r: '%s %s' % (r.branch.address, r.room_no))
or if want to use a single function (not tested):
def format_room(record):
return '%s %s' % (record.branch.address, record.room_no)
...
Field('room', 'reference room', requires=IS_IN_DB(..., label=format_record),
represent=lambda id, r: format_record(r.room))
Anthony
On Friday, March 22, 2013 2:14:31 AM UTC-4, 黄祥 wrote:
>
> thank you so much for your hint, anthony, but when i test it both of it
> return an error, any idea about this?
>
> IS_IN_DB(db(db.room.status=='Available'), db.room.id,
> label=lambda r: '%s %s' % (r.room.branch.address, r.room.room_no))
> Traceback
>
> 1.
> 2.
> 3.
> 4.
> 5.
> 6.
> 7.
> 8.
> 9.
> 10.
> 11.
> 12.
> 13.
> 14.
> 15.
> 16.
> 17.
> 18.
> 19.
> 20.
> 21.
> 22.
>
> Traceback (most recent call last):
> File "/home/stifank/Desktop/web2py/gluon/restricted.py", line 212, in
> restricted
> exec ccode in environment
> File
> "/home/stifank/Desktop/web2py/applications/hotel/controllers/default.py"
> <http://127.0.0.1:8000/admin/default/edit/futsal/controllers/default.py>,
> line 181, in <module>
> File "/home/stifank/Desktop/web2py/gluon/globals.py", line 194, in <lambda>
> self._caller = lambda f: f()
> File "/home/stifank/Desktop/web2py/gluon/tools.py", line 2971, in f
> return action(*a, **b)
> File
> "/home/stifank/Desktop/web2py/applications/hotel/controllers/default.py"
> <http://127.0.0.1:8000/admin/default/edit/futsal/controllers/default.py>,
> line 99, in booking
> editable=has_membership, deletable=has_membership)
> File "/home/stifank/Desktop/web2py/gluon/sqlhtml.py", line 2084, in grid
> search_menu = SQLFORM.search_menu(sfields, prefix=prefix)
> File "/home/stifank/Desktop/web2py/gluon/sqlhtml.py", line 1663, in
> search_menu
> for k,v in field.requires.options()],
> File "/home/stifank/Desktop/web2py/gluon/validators.py", line 545, in
> options
> self.build_set()
> File "/home/stifank/Desktop/web2py/gluon/validators.py", line 542, in
> build_set
> self.labels = [self.label(r) for r in records]
> File
> "/home/stifank/Desktop/web2py/applications/hotel/models/db_wizard_requires.py"
>
> <http://127.0.0.1:8000/admin/default/edit/futsal/models/db_wizard_requires.py>,
> line 57, in <lambda>
> label=lambda r: '%s %s' % (r.room.branch.address, r.room.room_no))
> AttributeError: 'Row' object has no attribute 'room'
>
>
> put in db.py
> def format_room(record):
> return '%s %s' % (record.room.branch.address, record.room.room_no)
>
>
> Traceback
>
> 1.
> 2.
> 3.
> 4.
> 5.
> 6.
> 7.
> 8.
> 9.
> 10.
> 11.
> 12.
> 13.
> 14.
> 15.
> 16.
> 17.
> 18.
> 19.
> 20.
> 21.
> 22.
>
> Traceback (most recent call last):
> File "/home/stifank/Desktop/web2py/gluon/restricted.py", line 212, in
> restricted
> exec ccode in environment
> File
> "/home/stifank/Desktop/web2py/applications/hotel/controllers/default.py"
> <http://127.0.0.1:8000/admin/default/edit/futsal/controllers/default.py>,
> line 181, in <module>
> File "/home/stifank/Desktop/web2py/gluon/globals.py", line 194, in <lambda>
> self._caller = lambda f: f()
> File "/home/stifank/Desktop/web2py/gluon/tools.py", line 2971, in f
> return action(*a, **b)
> File
> "/home/stifank/Desktop/web2py/applications/hotel/controllers/default.py"
> <http://127.0.0.1:8000/admin/default/edit/futsal/controllers/default.py>,
> line 99, in booking
> editable=has_membership, deletable=has_membership)
> File "/home/stifank/Desktop/web2py/gluon/sqlhtml.py", line 2084, in grid
> search_menu = SQLFORM.search_menu(sfields, prefix=prefix)
> File "/home/stifank/Desktop/web2py/gluon/sqlhtml.py", line 1663, in
> search_menu
> for k,v in field.requires.options()],
> File "/home/stifank/Desktop/web2py/gluon/validators.py", line 545, in
> options
> self.build_set()
> File "/home/stifank/Desktop/web2py/gluon/validators.py", line 542, in
> build_set
> self.labels = [self.label(r) for r in records]
> File "/home/stifank/Desktop/web2py/applications/hotel/models/db_wizard.py"
> <http://127.0.0.1:8000/admin/default/edit/futsal/models/db_wizard.py>, line
> 7, in format_room
> return '%s %s' % (record.room.branch.address, record.room.room_no)
> AttributeError: 'Row' object has no attribute 'room'
>
>
>
>
>
>>>
--
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.