Opened 8 years ago

Closed 8 years ago

Last modified 5 years ago

#8101 closed (fixed)

Admin boolean filter

Reported by: Alexander Owned by: Malcolm Tredinnick
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 Gary Wilson)

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.
patch
8101_boolean_fields_fix.diff (1.8 KB) - added by Brian Rosner 8 years ago.

Download all attachments as: .zip

Change History (13)

Changed 8 years ago by Alexander

Attachment: bool.diff added

patch

comment:1 Changed 8 years ago by Brian Rosner

milestone: 1.0 beta1.0
Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset

comment:2 Changed 8 years ago by Brian Rosner

Triage Stage: UnreviewedAccepted

comment:3 Changed 8 years ago by Brian Rosner

Needs tests: set
Patch needs improvement: set

Changed 8 years ago by Brian Rosner

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 Gary Wilson

Description: modified (diff)

comment:6 Changed 8 years ago by James Bennett

Resolution: duplicate
Status: newclosed

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: Core frameworkAdmin interface
Resolution: duplicate
Status: closedreopened

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 Malcolm Tredinnick

Owner: changed from nobody to Malcolm Tredinnick
Status: reopenednew

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 Malcolm Tredinnick

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 Malcolm Tredinnick

Resolution: fixed
Status: newclosed

Fixed in [8691].

comment:11 Changed 5 years ago by Jacob

milestone: 1.0

Milestone 1.0 deleted

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