Opened 5 years ago

Closed 5 years ago

#15606 closed (fixed)

Django admin filter and Bool choices

Reported by: django@… Owned by: nobody
Component: contrib.admin Version: 1.2
Severity: Keywords:
Cc: mir@… Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


If I have such construction:

class BoolTest(models.Model):
    NO = False
    YES = True
        (NO, 'no'),
        (YES, 'yes')
    completed = models.BooleanField(

class BoolTestAdmin(admin.ModelAdmin):
    list_filter = ('completed',)

and I use filter results in Django admin, then this URL is generated (for no and yes choices):


The True/False is taken as string (not converted 'True' -> True and 'False' -> False), non empty strings in Python are considered as True, so the final SQL is for both choices:

SELECT,, appname_booltest.completed FROM appname_booltest WHERE appname_booltest.completed = 1 ORDER BY DESC

I think, that instead of True/False there should be 0/1 in URL

Change History (2)

comment:1 Changed 5 years ago by russellm

  • Component changed from Uncategorized to django.contrib.admin
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

The problem here is the fact that you've used choices on a BooleanField; as a result of this, the "choices" filterspec is used, rather than the "boolean" filterspec.

This can be corrected by registering the Boolean filterspec first -- that way, the Boolean field will always get the 0/1 filter required by a boolean field.

comment:2 Changed 5 years ago by russellm

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

In [15817]:

Fixed #15606 -- Ensured that boolean fields always use the Boolean filterspec. Thanks to Martin Tiršel for the report

Note: See TracTickets for help on using tickets.
Back to Top