There's a validator if you want to save a slug to the DB:
http://web2py.com/book/default/chapter/07?search=IS_SLUG

Here's how I do it. I have a computed field for my records:

def slug(self):
    return '%s-%s' % (urlify(self.item.title, max_length=50), self.item.id)

And a function to return the id from a slug:

def id_from_slug(slug):
    id = slug.split('-')[-1]
    if id.isdigit():
        return id
    else:
        return None

So I can do things like:
<a href="{{=URL('default', 'item', extension='', args=item.slug)}}">
and
item = db(db.item.id==id_from_slug(request.args(0))).select().first()


Reply via email to