Opened 8 years ago

Closed 8 years ago

Last modified 5 years ago

#8101 closed (fixed)

Admin boolean filter

Reported by: Alexander Owned by: mtredinnick
Component: contrib.admin Version: master
Severity: Keywords: bool filter string
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: yes Patch needs improvement: yes
Easy pickings: UI/UX:

Description (last modified by gwilson)

Checked out revision 8204:

Filter for BooleanField not work...
Checked /admin/auth/user/?is_staff__exact=0
This is equals /admin/auth/user/?is_staff__exact=1

Also User.objects.filter(is_staff__exact='0') is bad result.

Please, Anybody fixed this bug in BooleanField().get_db_prep_value()

Attachments (2)

bool.diff (865 bytes) - added by Alexander 8 years ago.
8101_boolean_fields_fix.diff (1.8 KB) - added by brosner 8 years ago.

Download all attachments as: .zip

Change History (13)

Changed 8 years ago by Alexander


comment:1 Changed 8 years ago by brosner

  • milestone changed from 1.0 beta to 1.0
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

comment:2 Changed 8 years ago by brosner

  • Triage Stage changed from Unreviewed to Accepted

comment:3 Changed 8 years ago by brosner

  • Needs tests set
  • Patch needs improvement set

Changed 8 years ago by brosner

comment:4 Changed 8 years ago by magneto

this relates to #8062 where all the filter args are now casted

comment:5 Changed 8 years ago by gwilson

  • Description modified (diff)

comment:6 Changed 8 years ago by ubernostrum

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

Following up on magneto's comment, this appears to be the same underlying problem as #8062.

comment:7 Changed 8 years ago by mattdw

  • Component changed from Core framework to Admin interface
  • Resolution duplicate deleted
  • Status changed from closed to reopened

There's still a problem here, but I'm guessing it's probably something that needs to be dealt with in the contrib.admin.

To clarify, if you have a BooleanField in a ModelAdmin.list_filter = [...], currently that filter will always show only field=True records. I imagine this is because ?field__exact=0 in the url translates to '0', and bool('0') == True. A current workaround is to hack the url to '?field__exact='.

comment:8 Changed 8 years ago by mtredinnick

  • Owner changed from nobody to mtredinnick
  • Status changed from reopened to new

In line with a conversation Jacob and I had earlier today, the ticket this was marked as a dupe of was wontfixed because it's not clear that everything needs to be cast. So brosner's patch here is pretty much the right thing. However, before committing, I want to work out why BooleanField is allowing such a broad expanse of wild things as booleans. That's just too loose and I suspect some of it is a holdover from pre-historical days.

comment:9 Changed 8 years ago by mtredinnick

Turns out we shouldn't really use to_python() in the call there; it allows too much stuff and to_python() has a different goals (e.g. deserialization). That discrepancy will probably be sorted out with model-aware validation, since that requires normalisation as well. For now, I've written a get_db_prep_lookup() method that does the right thing in these cases.

comment:10 Changed 8 years ago by mtredinnick

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

Fixed in [8691].

comment:11 Changed 5 years ago by jacob

  • milestone 1.0 deleted

Milestone 1.0 deleted

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