[web2py] Tag handling suggestions
Anyone have a quick perspective on the pros/cons of handling tags like this: Option 1: db.define_table('item',Field('tags','list:string')) Option 2: db.define_table('tag') db.define_table('item',Field('tags','list:reference tag')) Options 3: db.define_table('item') db.define_table('tag') db.define_table('item_tag',Field('item'),Field('tag'))
Re: [web2py] Tag handling suggestions
On Mon, Oct 10, 2011 at 9:36 PM, pbreit pbreitenb...@gmail.com wrote: Option 1: db.define_table('item',Field('tags','list:string')) I am using the Option 1. for me it is better because I end with pure Python list, which I can run map, reduce, filter etc... also contains and belongs are very helpful and fast. I also think it is the less complicated way. -- Bruno Rocha [ About me: http://zerp.ly/rochacbruno ] [ Aprenda a programar: http://CursoDePython.com.br ]
Re: [web2py] Tag handling suggestions
Clarifying: Option 1: db.define_table('item',Field('tags','list:string')) *Pro*: Easy search: tag = request.args(0) results = db(db.item.tags.contains(tag)).select() *Con*: build a tag cloud records = db(db.item.id0).select(db.item.tags) alltags = [] # loop thought records to populate the tags list (here you can use reduce, list comprehension) Option 2: db.define_table('tag') db.define_table('item',Field('tags','list:reference tag')) *Pro*: build a tag clous alltags = [ r.tag for r in db(db.tag.id0).select('tag')] *Con:* Search is expensive tag = request.args(0) # it is a string like: book tag_id = db.tag(tag=tag)[0].id # or a taglist records = db(db.item.tag.contains(tag_id)).select() Options 3: db.define_table('item') db.define_table('tag') db.define_table('item_tag',Field('item'),Field('tag')) *Con:* In this case I see Tag searching and tagcloud as a expensive process. But, certainly Massimo has a DAL trick to solve this use case in one line of code ;) -- Bruno Rocha [ About me: http://zerp.ly/rochacbruno ] [ Aprenda a programar: http://CursoDePython.com.br ]