I went for the virtual field approach.

My field in my model:
#Virtual field for showing categories in view
def categories(row):
    links = db(db.post_to_cat.post_id == row.blog_post.id).select()
    ids = [{'name':l.cat_id.name, 'slug':l.cat_id.slug} for l in links]
    return ids

#Appending the virtual field to blog_post table
db.blog_post.categories = Field.Virtual('categories', categories)

And in the view:
{{for p in posts:}}
   {{for c in p.categories:}}
      <a href="{{=URL('blog', 'index', args=p['slug'])}}">{{=c['name']}}</a>
   {{pass}}
{{pass}}



-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
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 web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to