tags:

views:

42

answers:

1

So this is almost a duplicate of this question, except that I do want to use the slug for lookup.

My URLs look like this:

http://url.com/county/place-name

The unique combination of 'county' and 'place-name' is used to look up the database object, except that 'place-name' is stored in the database as 'Place Name'.

So if I don't store place-name in the database as a separate slug field, I would need to de-slugify it first, and only then then do lookup.

Is de-slugification safe/possible in Django? Or would I be better off adding a place-name slug field to my database, and populating it whenever a new object gets added?

+3  A: 

I'd always safe it in the database if used for lookup: Broken URLs are to be avoided, just in case you need to change the placename. If later you need for any reason to change the slugification algorithm, at least old data won't break. Etc.

If you need to change slugs later, you can at least deal with the migration while still having the old slugs saved.

chryss
I'd add to cryss's answer - that you might even have an extra table to store association of slugs with objects - because there might be synonyms in the future and you will be able to set up proper redirects to "canonical" urls that show the proper record.
Evgeny
Yup, I'm setting out to do just that these days on an old project with some very ugly slugs.
chryss