Code

#18525 closed Cleanup/optimization (wontfix)

unique should be True by default on SlugField instead of False.

Reported by: anonymous Owned by: nobody
Component: Database layer (models, ORM) Version:
Severity: Normal Keywords: SlugField
Cc: meshy Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

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.

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)

Attachments (0)

Change History (2)

comment:1 Changed 22 months ago by meshy

  • Cc meshy added
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

Oops! I hit "Post" instead of "Preview". I posted this.

comment:2 Changed 22 months ago by kmtracey

  • Resolution set to wontfix
  • Status changed from new to closed

Even if this were not backwards incompatible, it doesn't strike me as a good idea. Having the framework decide for me that "oh you probably want this to be unique" isn't something that appeals to me, nor is having to start keeping track of "these fields have unique=True by default, unlike most fields". While it may be quite common for for unique=True on a SlugField it's not nearly universal: unique together with another field is likely also quite common.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.