Hard to say the best way to do it. This might be one way (not tested). === controller === def index(): pages = db(db.page.id>0).select(orderby = db.page.title) comments = db(db.comment.id>0).select() return dict(pages=pages, comments=comments)
=== view === <ol> {{for page in page:}} <li>{{=page.name}}<br> <ol>{{for comment in comments if comment.page_id==page.id:}} <li>{{=comment.body}}</li> {{pass}} </ol> </li> {{pass}} </ol> There's probably a much more efficient way to do it since the "for comment in comments" loop goes through all comments for each page. The way you had it didn't really make any sense because you were getting all the pages but then just the comments for one (unspecified) page. "db(db.comment.page_id == db.page.id).select()" is going to return ALL comments. If you want the comments for just one page you would do something like db(db.comment.page_id == r <http://db.page.id/>equest.args(0)).select(). To make it more efficient, you might be able to group the comments in the controller. I don't know if this works, it's kind of a guess. def index(): pages = db(db.page.id>0).select(orderby = db.page.title) comments = db(db.comment.id>0).select() for comment in comments: comment_groups[coment.page_id].append(comment) return dict(pages=pages, comment_groups=comment_groups) <ol> {{for page in page:}} <li>{{=page.name}}<br> <ol>{{for comment in comment_groups[page.id]:}} <li>{{=comment.body}}</li> {{pass}} </ol> </li> {{pass}} </ol>