You can just replace <td>{{=event.room_id}}</td>
with <td>{{=event.room_id.name}}</td> This will result in one extra select per record. You can also use a join #default.py def index(): events = db(db.events.room_id==db.rooms.id).select(orderby=db.events.event_date) return dict(events=events) #index.html {{extend 'layout.html'}} <table> <tr> <td>Date</td><td>Event</td><td>Room</td> </tr> {{for e in events:}} <tr> <td>{{=e.events.event_date}}</td><td>{{=e.events.title}}</ td><td>{{=e.rooms.id}}</td> </tr> {{pass}} </table> These kind of programs read better if table names are singular. ;-) Massimo On Mar 22, 5:45 pm, Greg <greg.kr...@gmail.com> wrote: > Hello! > > I have a view that lists some records (events), one of the fields > (events.room_id) is a foreign key. When i display these records I want > to display rooms.name, not events.room_id. Can someone give me a nudge > (or swift kick) in the right direction on how to do this? I suspect a > join of some sort is required, but that stuff confuses the hell out of > me. I've included some relevant code below. > > Thanks! > > #db.py > db.define_table('rooms', > Field('name'), > ) > > db.define_table('events', > Field('title'), > Field('event_date', 'date'), > Field('room_id', db.rooms) > ) > > #default.py > def index(): > events = db().select(db.events.ALL, orderby=db.events.event_date) > return dict(events=events) > > #index.html > {{extend 'layout.html'}} > <table> > <tr> > <td>Date</td><td>Event</td><td>Room</td> > </tr> > {{for event in events:}} > <tr> > <td>{{=event.event_date}}</td><td>{{=event.title}}</ > td><td>{{=event.room_id}}</td> > </tr> > {{pass}} > </table> -- You received this message because you are subscribed to the Google Groups "web2py-users" group. To post to this group, send email to web...@googlegroups.com. To unsubscribe from this group, send email to web2py+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/web2py?hl=en.