On Wednesday, June 27, 2012 7:15:03 AM UTC-4, Meshy wrote: > > Perhaps it's just me, but I've very rarely wanted a SlugField that wasn't > unique. Would this not be a sensible default? I realise that a lot of apps > will rely upon this default, but objectively speaking would this not be > better? Perhaps this change would be appropriate for django 2.0. > > At the moment, slug = models.SlugField()creates a non-unique field, and > if you want it to be unique, then you must add unique=True. I feel this > is wrong. > > It seems to me that unique should be default, and if you don't want a > unique slug, you should explicitly state that: > slug = models.SlugField(unique=False) >
I'd agree that slugs are often unique, but I think it's just as common that they are unique together with another field (think blogs -- /blog/2012/06/27/some-slug/ -- where the slug is unique_together with the date). For this case, you'd have to remember to specify unique=False *and* unique_together. > I've added an issue on the tracker for this: > https://code.djangoproject.com/ticket/18525 > > I realise this may be a contentious issue...or that I may even get shot > down in flames on this one ;P Go easy on me! :) > > What do you all think? > It doesn't seem like a burden to have to say unique=True if you truly want a singularly unique slug. Making it explicit, aside from being good python zen, also helps to see the natural keys of your model at a glance. Dan -- You received this message because you are subscribed to the Google Groups "Django developers" group. To view this discussion on the web visit https://groups.google.com/d/msg/django-developers/-/8V3D_HcVhf8J. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/django-developers?hl=en.
