Thank you Massimo! works very well. I just needed to change a little in
order to get the brand.name instead brand.id in the slug

This:

def get_brand(r):
    import re
    brand = db(db.brand.id==r.brand).select().first()
    slug_regex = re.compile('[^\w-]')
    return slug_regex.sub('',brand.nome+'-%(model)s-%(year)s' %r).lower()

and:

Field('slug', notnull=True, compute= lambda r: get_brand(r)),

to get: 'toyota-corolla-2010' as slug  ( I still wants to get the r.id at
the end)

Tks.

2010/8/15 mdipierro <mdipie...@cs.depaul.edu>

> 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)
>



-- 

http://rochacbruno.com.br

Reply via email to