Django slugified urls - how to handle collisions?
collision, django, python, slug, url
Solution
One thing I never liked about the unique slug fields/methods is that if you have a lot of clashes for a single title, you'll end up running several queries to try and determine an available slug. I know you mentioned you don't want to show the id for non-clashing slugs, but, as far as performance, I think it's the better route to take. To make the URL a little nicer looking, I prefer also to embed the id before the slug, so that a URL takes the form of www.example.com/reviews/1/the-best-thing-ever.
Problem
I'm currently working on a toy project in Django. Part of my app allows users to leave reviews. I'd like to take the title of the review and slugify it to create a url. So, if a user writes a review called "The best thing ever!", the url would be something like: `www.example.com/reviews/the-best-thing-ever`. That's all well and good, but what is the best way to handle case where two users pick the same title? I don't want to make the title required to be unique. I've thought about adding the review id in the url somewhere, but I'd like to avoid that extra info for any urls that don't collide. Any ideas?