[Catalyst] Slug Generator?

Kevin Monceaux Kevin at RawFedDogs.net
Fri Feb 22 23:32:37 GMT 2013


On Fri, Feb 22, 2013 at 07:25:00PM -0300, Hernan Lopes wrote:

> http://search.cpan.org/~rentocron/Text2URI-0.3001/
> 
> that will do it

It looks like that would handle simple cases where the slug is being
generated from a unique column.  But, life usually isn't simple.  Here are
some examples from my site, which is currently Django based and using
Django-autoslug:

    http://www.RawFedDogs.net/MyPhotoAlbum/Misc/Photo/Czar/

    http://www.RawFedDogs.net/MyPhotoAlbum/Misc/Photo/Czar-2/

    http://www.RawFedDogs.net/MyPhotoAlbum/Misc/Photo/Czar-6/

    http://www.RawFedDogs.net/MyPhotoAlbum/October-2001/Photo/Czar/

    http://www.RawFedDogs.net/MyPhotoAlbum/December-2004/Photo/Czar/

    http://www.RawFedDogs.net/MyPhotoAlbum/December-2004/Photo/Czar-2/

    http://www.RawFedDogs.net/MyPhotoAlbum/December-2004/Photo/Czar-3/

    http://www.RawFedDogs.net/Recipe/Pork-Roast/Photo/Czar/

    http://www.RawFedDogs.net/Recipe/Pork-Roast/Photo/Czar-2/

Czar, Czar-2, Czar-3, etc., are the slugs for the photo model.  The slug
field is defined as:

    Slug = AutoSlugField(populate_from='Title', 
                         unique_with=['content_type', 'object_id'],
                         always_update=True)

All of the above photos have the same title - Czar.  AutoSlug adds the
numbers to the end of the slug if needed to make them unique.  The photo
model is polymorphic.  Photos can be attached to albums, recipes, and/or
terms.  unique_with=['content_type', 'object_id'] causes AutoSlug to check
the parent's ID and type when determining if the slug is unique or not.  


-- 

Kevin
http://www.RawFedDogs.net
http://Lassie.RawFedDogs.net
http://www.WacoAgilityGroup.org
Bruceville, TX

What's the definition of a legacy system? One that works!
Errare humanum est, ignoscere caninum.



More information about the Catalyst mailing list