Django: better to save a slug to the DB or generate dynamically, if used for lookup?
So this is almost a duplicate of this question, except that I do want to use the slug for lookup.
My URLs loo开发者_运维技巧k 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?
I'd always save it to the database if it's 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.
精彩评论