I understand and what you need to do is a bit more complex than needs
to be. For this reason we have plugin_tagging and tagging in
plugin_wiki. Another approach is the following...

class TAGGING:
    def __call__(self,field,value):
          return INPUT(_name='%s_%s' % (field._tablename,field.name),
                       _value=', '.join(r.name for r in
db(db.tag.id.belongs(value or [])).select()),
                       requires = self.validate)
    def validate(self,tags):
          names = [x.strip() for x in tags.split(',')]
          ids = [r.id for r in
db(db.tag.name.belongs(names)).select()]
          if len(ids) < len(names):
              return (ids, "one of the tags is invalid or repeated")
          return (ids,None)

db.define_table('tag',
                Field('name', requires=IS_NOT_EMPTY()), format='%
(name)s')
db.define_table('product',
                Field('name', requires=IS_NOT_EMPTY()),
                Field('tags', 'list:reference tag',widget=TAGGING()),)

def testme():
    return {
        'a': crud.update(db.product, request.args(0)),
        'b': crud.select(db.product),
        }

The custom TAGGING widget renders the list of IDS as a a list of comma-
separated names. You can also cache the mapping between ids and tag
names for speed.

Reply via email to