Django

Code

Ticket #2723 (assigned)

Opened 2 years ago

Last modified 3 months ago

yes/no option for BooleanField

Reported by: Gary Wilson <gary.wilson@gmail.com> Assigned to: shanx (accepted)
Milestone: post-1.0 Component: django.contrib.admin
Version: SVN Keywords: nfa-someday, sprintdec01, sprint-pycon08
Cc: Triage Stage: Accepted
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 1

Description

It would be nice to have the same sort of yes/no dropdown/radio option for BooleanField? that NullBooleanField? does (without the "unknown" choice of course). I think there are instances where this sort of interface works better than a checkbox. Adrian likes the radio option. google groups thread.

Attachments

booleanwidget_radio.diff (1.8 kB) - added by dtulig on 12/01/07 19:16:59.
Adds a custom boolean field widget to the admin interface.
booleanwidget_radio_with_tests.2.diff (9.4 kB) - added by shanx on 03/17/08 16:22:24.
Improved patch with tests
booleanwidget_radio_with_tests.diff (9.4 kB) - added by shanx on 03/17/08 16:22:31.
Improved patch with tests

Change History

02/21/07 15:09:30 changed by Michael Radziej <mir@noris.de>

  • stage changed from Unreviewed to Design decision needed.

08/13/07 00:04:55 changed by anonymous

  • status changed from new to closed.
  • needs_better_patch set to 1.
  • component changed from Admin interface to django-admin.py.
  • version set to SVN.
  • needs_docs set to 1.
  • resolution set to invalid.

08/13/07 00:39:58 changed by ubernostrum

  • status changed from closed to reopened.
  • needs_better_patch deleted.
  • component changed from django-admin.py to Admin interface.
  • resolution deleted.
  • needs_docs deleted.

Reverting spam close.

10/26/07 17:32:34 changed by SmileyChris

  • stage changed from Design decision needed to Accepted.

Shouldn't be hard to do in newforms-admin. Adrian likes it. Let's promote to accepted.

12/01/07 19:16:59 changed by dtulig

  • attachment booleanwidget_radio.diff added.

Adds a custom boolean field widget to the admin interface.

12/01/07 19:17:37 changed by dtulig

  • keywords set to newforms-admin, sprintdec01.
  • owner changed from nobody to dtulig.
  • has_patch set to 1.
  • status changed from reopened to new.

03/17/08 11:14:57 changed by shanx

  • owner changed from dtulig to shanx.
  • status changed from new to assigned.

03/17/08 16:20:31 changed by shanx

  • keywords changed from newforms-admin, sprintdec01 to newforms-admin, sprintdec01, sprint-pycon08.
  • stage changed from Accepted to Ready for checkin.

See attached improved patch + unit test. Unit tests check out and have been run against sqlite (since there is no db specific things going on here I deemed that to be enough)

I've changed the naming to AdminBooleanSelectWidget? for the widget itself, to match the naming pattern of other widget.

The widget uses it's own RadioFieldRenderer?, this is done to enable the <ul> that will be rendered to use the css plainlist layout, otherwise both radioselects would be rendered with square bullets in front of them in the Admin.

Also added are tests to see whether the hooks in BaseModelAdmin? work (those that bind specific widgets to certain fields), to booleanfield is of course tested.

03/17/08 16:22:24 changed by shanx

  • attachment booleanwidget_radio_with_tests.2.diff added.

Improved patch with tests

03/17/08 16:22:31 changed by shanx

  • attachment booleanwidget_radio_with_tests.diff added.

Improved patch with tests

03/18/08 09:21:25 changed by mtredinnick

  • version changed from SVN to newforms-admin.

04/04/08 03:36:10 changed by anonymous

  • keywords changed from newforms-admin, sprintdec01, sprint-pycon08 to nfa-someday, sprintdec01, sprint-pycon08.

06/17/08 11:53:16 changed by programmerq

  • milestone set to 1.0.

08/08/08 12:53:44 changed by peterd12

Why hasn't this been checked in? It seems like it's ready. I'd really like this feature without having to patch Django.

08/15/08 16:45:23 changed by anonymous

  • version changed from newforms-admin to SVN.

08/22/08 16:27:45 changed by brosner

  • milestone changed from 1.0 to post-1.0.

This can be easily done without patching Django and it really is a new feature and not fixing a bug. Marking post-1.0.

09/29/08 22:12:50 changed by mtredinnick

  • needs_better_patch set to 1.
  • stage changed from Ready for checkin to Accepted.

This shouldn't be supplying a widget only for the admin interface. Will no other application ever use boolean fields? If we're adding a widget, it's generally going to either be worthy of putting into django/forms/widgets.py or not including at all; there are very few cases when a specialised widget just for admin is appropriate.

So, let's move the widget to a more useful place.

Secondly, the tests here are kind of confusing (all the hooked widget stuff). They seem to be trying to enforce something about admin widget overrides that I'm not sure is actually correct (why can't those things ever change?). Whilst tests are good, those tests aren't testing that this widget behaves correctly; they're trying to test some other incidental behaviour. So let's move those to another patch so that when we resolve how to do better custom widget overrides in admin they can be part of that. At the moment they're distracting a bit from the issue at hand and I'm not sure that if they were to fail it would actually mean there's a problem in Django's public behaviour (they're internal implementation details, as far as I can tell).

Thirdly, it looks unnecessary to have strings like u'1' for the choices. Just use integers there. The point is that there's no need to do all this forcing to strings and it makes the reader wonder why you're doing that. If you used 0 and 1 for the choice values, then you'd simplify a lot of the code, too, since bool(value) would give the right integer -> boolean conversion and int(value) would give the right choice value for both boolean and integer input.

Finally, please don't mark your own patches as "ready for checkin". I suspect this went unreviewed for so long because it was in that state and we hadn't realised it hadn't been through a review.


Add/Change #2723 (yes/no option for BooleanField)




Change Properties
Action