IS_IN_DB(....,multiple=True)
sorry still undocumented is a portable (on GAE) way to do many to many. it does not use an intermediate table. It stores all keys in the field like in |3|5|7| etc etc. It is used for example to select tutorials in the Pycon registration page (using the jquery multiselect plugin). Using db.table.field.widget you can change the way any field is rendered by SQLFORM. I am using the T2 tag_widget function. Massimo On Feb 7, 7:04 pm, mickgardner <mickgard...@gmail.com> wrote: > Thanks so much for the response. > Could you explain what you're doing there a little ? > I've had a go at using that, for example the many to one table but > unsure how / where the widget function works or is implemented? > > thanks > Michael > > On Feb 8, 2:09 am, mdipierro <mdipie...@cs.depaul.edu> wrote: > > > db.define_table('tag',dbField('name')) > > > db.define_table('taggable,db.Field('description'),db.Field > > ('tags','text')) > > > db.taggable.tags.requires=IS_IN_DB(db,'tag.id','%(name) > > s',multiple=True) > > > Optional: > > > def tag_widget(self,value,tags=[]): > > script=SCRIPT > > (""" > > function web2py_tag(self,other,tag) > > { > > var o=document.getElementById > > (other) > > if(self.className=='tag_on') > > { > > self.setAttribute > > ('class','tag_off'); > > o.value=o.value.replace('|'+tag > > +'|','|'); > > } else if(self.className=='tag_off') > > { > > self.setAttribute > > ('class','tag_on'); > > o.value=o.value+'|'+tag > > +'|'; > > } > > }""") > > id=self._tablename+'_'+self.name > > def onclick(x): return "web2py_tag(this,'%s','%s');"%(id,x) > > if tags and not isinstance(tags[0],(list,tuple)): tags=[tags] > > buttons=[DIV(_class='tag_row', > > *[SPAN(A(x,_class='tag_on' if value and '|%s|'%x \ > > in value else 'tag_off',_onclick=onclick(x)),\ > > _class="tag_col") for x in tag_line]) for tag_line in > > tags] > > return DIV(script,INPUT(_type='hidden',_id=id,_name=self.name, > > _value=value),*buttons) > > > db.tagging.tags.widget=tag_widget > > > Massimo > > > On Feb 7, 4:44 am, mickgardner <mickgard...@gmail.com> wrote: > > > > Hi, > > > > i've been trying all day to work out how to do this and cannot get it > > > working completely the way I want it to. > > > > I'm building a blog and want to implement tagging. > > > The tagging would work as such: > > > > There would be a text, tagging field that would accept multiple comma > > > or space separated 'tags'. > > > > each word or tag would then be listed with each post, > > > each word would be a hyperlinked so that when its clicked on it would > > > list all articles that have that tag on it. > > > > Now I can get this working, if I have one word only. When I use spaces > > > and or multiple words / tags the system rightfully treats it as one > > > tag. > > > > I'm trying to work out how to accept multiple tags in one field and > > > have them treated as multiple tags not one giant tag with spaces. > > > I was thinking that perhaps I could use some sort of custom validator > > > or something behind the form that split the words up so that they were > > > treated separately but cannot figure it. > > > > Any assistance / advice would be welcome! > > > > thanks > > > Michael Gardner --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "web2py Web Framework" group. To post to this group, send email to web2py@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 -~----------~----~----~----~------~----~------~--~---