Django

Code

Ticket #8101 (closed: fixed)

Opened 4 months ago

Last modified 3 months ago

Admin boolean filter

Reported by: Alexander Assigned to: mtredinnick
Milestone: 1.0 Component: django.contrib.admin
Version: SVN Keywords: bool filter string
Cc: Triage Stage: Accepted
Has patch: 1 Needs documentation: 0
Needs tests: 1 Patch needs improvement: 1

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

bool.diff (0.8 kB) - added by Alexander on 08/03/08 23:39:00.
patch
8101_boolean_fields_fix.diff (1.8 kB) - added by brosner on 08/04/08 12:32:35.

Change History

08/03/08 23:39:00 changed by Alexander

  • attachment bool.diff added.

patch

08/04/08 11:11:39 changed by brosner

  • needs_better_patch changed.
  • needs_docs changed.
  • needs_tests changed.
  • milestone changed from 1.0 beta to 1.0.

08/04/08 11:11:53 changed by brosner

  • stage changed from Unreviewed to Accepted.

08/04/08 12:05:47 changed by brosner

  • needs_better_patch set to 1.
  • needs_tests set to 1.

08/04/08 12:32:35 changed by brosner

  • attachment 8101_boolean_fields_fix.diff added.

08/04/08 12:42:54 changed by magneto

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

08/05/08 08:55:47 changed by gwilson

  • description changed.

08/22/08 17:24:32 changed by ubernostrum

  • status changed from new to closed.
  • resolution set to duplicate.

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

08/28/08 20:53:43 changed by mattdw

  • status changed from closed to reopened.
  • resolution deleted.
  • component changed from Core framework to Admin interface.

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='.

08/28/08 21:03:26 changed 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.

08/28/08 21:39:47 changed 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.

08/28/08 21:41:47 changed by mtredinnick

  • status changed from new to closed.
  • resolution set to fixed.

Fixed in [8691].


Add/Change #8101 (Admin boolean filter)




Change Properties
Action