#29631: Feature Request: models.UniqueBooleanField()
-------------------------------------+-------------------------------------
     Reporter:  Michael              |                    Owner:  nobody
         Type:  New feature          |                   Status:  closed
    Component:  Database layer       |                  Version:  2.1
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:  wontfix
     Keywords:                       |             Triage Stage:
                                     |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by Simon Charette):

 I'd add that the usual way to implement such a feature is using a partial
 composite unique index which is something #29547 is trying to add support
 for.

 In the mean time you can enforce it at the database level using a
 `RunSQLOperation`.

 {{{#!sql
 CREATE UNIQUE INDEX pinned_tweet ON tweet (user_id, pinned) WHERE pinned =
 true;
 }}}

 If your database doesn't support partial index a workaround would be to
 declare your `pinned` field as `NULL`able and use `NULL` as the ''falsey''
 value as it will be ignored in unique constraints.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/29631#comment:2>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/065.9329689e892b9c57a4aad80fe9a90636%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to