[web2py] Re: Displaying Foreign Key
Ah, very simple. Thanks, guys. P.S. It's a good thing web2py makes it easy to rename tables. :) On Mar 22, 6:07 pm, mdipierro mdipie...@cs.depaul.edu wrote: 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 tdDate/tdtdEvent/tdtdRoom/td /tr {{for e in events:}} tr td{{=e.events.event_date}}/tdtd{{=e.events.title}}/ tdtd{{=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 tdDate/tdtdEvent/tdtdRoom/td /tr {{for event in events:}} tr td{{=event.event_date}}/tdtd{{=event.title}}/ tdtd{{=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.
[web2py] Re: Displaying Foreign Key
Would this work in GAE which does not handle table join? or the DAL automatically handle this for you? -- 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.
[web2py] Re: Displaying Foreign Key
No joins on gae. On Mar 23, 6:12 pm, Al albertsec...@gmail.com wrote: Would this work in GAE which does not handle table join? or the DAL automatically handle this for you? -- 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.
[web2py] Re: Displaying Foreign Key
It's as simple as this: {{=event.room_id.name}} 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 tdDate/tdtdEvent/tdtdRoom/td /tr {{for event in events:}} tr td{{=event.event_date}}/tdtd{{=event.title}}/ tdtd{{=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.
[web2py] Re: Displaying Foreign Key
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 tdDate/tdtdEvent/tdtdRoom/td /tr {{for e in events:}} tr td{{=e.events.event_date}}/tdtd{{=e.events.title}}/ tdtd{{=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 tdDate/tdtdEvent/tdtdRoom/td /tr {{for event in events:}} tr td{{=event.event_date}}/tdtd{{=event.title}}/ tdtd{{=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.