Opened 16 years ago

Closed 16 years ago

Last modified 13 years ago

#8101 closed (fixed)

Admin boolean filter

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

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

Download all attachments as: .zip

Change History (13)

by Alexander, 16 years ago

Attachment: bool.diff added

patch

comment:1 by Brian Rosner, 16 years ago

milestone: 1.0 beta1.0

comment:2 by Brian Rosner, 16 years ago

Triage Stage: UnreviewedAccepted

comment:3 by Brian Rosner, 16 years ago

Needs tests: set
Patch needs improvement: set

by Brian Rosner, 16 years ago

comment:4 by magneto, 16 years ago

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

comment:5 by Gary Wilson, 16 years ago

Description: modified (diff)

comment:6 by James Bennett, 16 years ago

Resolution: duplicate
Status: newclosed

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

comment:7 by mattdw, 16 years ago

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 by Malcolm Tredinnick, 16 years ago

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 by Malcolm Tredinnick, 16 years ago

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 by Malcolm Tredinnick, 16 years ago

Resolution: fixed
Status: newclosed

Fixed in [8691].

comment:11 by Jacob, 13 years ago

milestone: 1.0

Milestone 1.0 deleted

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