import re slug_regex = re.compile('[^\w-]') Field('slug',compute=lambda r: slug_regex.sub('','%(brand)s-%(model)s-% (year)s' %r).lower())
On Aug 14, 11:12 pm, Bruno Rocha <rochacbr...@gmail.com> wrote: > I need a page slug for the cars in my car shop, > instead havinghttp://.../default/car/2, > I wanthttp://..../default/car/carbrand-carmodel-caryear-id > > so I defined a table: > > db.define_table('car' > Field('brand', db.brand), > Field('model'), > Field('year','integer'), > Field('slug') > ) > > but I do not want the user to fill the "slug" field, so I have to define > default value to the slug field, concatenating 'brand' + 'model' + 'year' + > 'slug' joining with a '-', > eg: > id = 2 > brand = 'Toyota' > model = 'Corolla' > year = '2010' > slug = 'toyota-corolla-2010-2' > > how can I get this to be automaticaly filled when inserting? (just like a > trigger)