#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 )
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)
Change History (13)
by , 17 years ago
comment:1 by , 17 years ago
| milestone: | 1.0 beta → 1.0 |
|---|
comment:2 by , 17 years ago
| Triage Stage: | Unreviewed → Accepted |
|---|
comment:3 by , 17 years ago
| Needs tests: | set |
|---|---|
| Patch needs improvement: | set |
by , 17 years ago
| Attachment: | 8101_boolean_fields_fix.diff added |
|---|
comment:5 by , 17 years ago
| Description: | modified (diff) |
|---|
comment:6 by , 17 years ago
| Resolution: | → duplicate |
|---|---|
| Status: | new → closed |
Following up on magneto's comment, this appears to be the same underlying problem as #8062.
comment:7 by , 17 years ago
| Component: | Core framework → Admin interface |
|---|---|
| Resolution: | duplicate |
| Status: | closed → 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 by , 17 years ago
| Owner: | changed from to |
|---|---|
| Status: | reopened → 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 by , 17 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.
patch