[Django] #27917: ModelAdmin rejects NullBooleanField as a valid radio_fields item

48 views
Skip to first unread message

Django

unread,
Mar 8, 2017, 10:02:16 PM3/8/17
to django-...@googlegroups.com
#27917: ModelAdmin rejects NullBooleanField as a valid radio_fields item
--------------------------------------------+------------------------
Reporter: Jerome Leclanche | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 1.10
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
--------------------------------------------+------------------------
How to reproduce:

- Create a model with a NullBooleanField "foo"
- Create and register a corresponding ModelAdmin instance for the model
- Add `radio_fields = {"foo": admin.HORIZONTAL}` to the model admin

It will be rejected with a SystemCheckError:

<class 'djstripe.admin.EventAdmin'>: (admin.E023) The value of
'radio_fields' refers to 'foo', which is not an instance of ForeignKey,
and does not have a 'choices' definition.

This is very unintuitive. I'm unsure why even it *needs* a choices
definition seeing as it has no problem rendering a <select> widget.

Relevant links:

- https://stackoverflow.com/questions/11990852/django-display-
nullbooleanfield-as-radio-and-default-to-none
- https://groups.google.com/forum/#!topic/django-users/HFU-ub1kDMw
- https://code.djangoproject.com/ticket/23681

--
Ticket URL: <https://code.djangoproject.com/ticket/27917>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Mar 9, 2017, 9:32:43 AM3/9/17
to django-...@googlegroups.com
#27917: Allow ModelAdmin.radio_fields to work with NullBooleanField
-------------------------------------+-------------------------------------

Reporter: Jerome Leclanche | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: contrib.admin | Version: 1.10
Severity: Normal | Resolution:

Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* type: Uncategorized => Cleanup/optimization
* component: Uncategorized => contrib.admin


Comment:

It's not as simple as removing the system check. Changes in
`BaseModelAdmin.formfield_for_dbfield` are also required to add support
for `NullBooleanField` in `radio_fields`. Fixing #23130, which deprecates
`NullBooleanField` in favor of allowing `null=True` on `BooleanField`, may
help or even completely solve this issue.

--
Ticket URL: <https://code.djangoproject.com/ticket/27917#comment:1>

Django

unread,
Mar 9, 2017, 10:31:24 AM3/9/17
to django-...@googlegroups.com
#27917: Allow ModelAdmin.radio_fields to work with NullBooleanField
--------------------------------------+------------------------------------

Reporter: Jerome Leclanche | Owner: nobody
Type: Cleanup/optimization | Status: new

Component: contrib.admin | Version: 1.10
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Tim Graham):

* stage: Unreviewed => Accepted


--
Ticket URL: <https://code.djangoproject.com/ticket/27917#comment:2>

Django

unread,
Apr 5, 2017, 5:22:21 AM4/5/17
to django-...@googlegroups.com
#27917: Allow ModelAdmin.radio_fields to work with NullBooleanField
--------------------------------------+------------------------------------
Reporter: Jerome Leclanche | Owner: Musen
Type: Cleanup/optimization | Status: assigned

Component: contrib.admin | Version: 1.10
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Musen):

* owner: nobody => Musen
* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/27917#comment:3>

Django

unread,
Apr 17, 2017, 6:16:37 AM4/17/17
to django-...@googlegroups.com
#27917: Allow ModelAdmin.radio_fields to work with NullBooleanField
--------------------------------------+------------------------------------
Reporter: Jerome Leclanche | Owner: Musen
Type: Cleanup/optimization | Status: assigned
Component: contrib.admin | Version: 1.10
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------

Comment (by Musen):

Tim, do you know the status of #23130? It seems to be inactive for 3
years. Do people come to the conclusion to deprecates `NullBooleanField`?

Also, I can see 2 ways to finish the ticket: one to hook NullBooleanField
and create a ChoieField with (('1', 'Unknow'), ('2', ‘Yes'), ('3', 'No')
instead (when it is in `radio_fields`); another is to create a
`NullBooleanRadioSelect` widget to handle this like the original
`NullBooleanSelect` widget. I am not which one is better or there could be
an even better way.

--
Ticket URL: <https://code.djangoproject.com/ticket/27917#comment:4>

Django

unread,
May 6, 2017, 3:14:38 PM5/6/17
to django-...@googlegroups.com
#27917: Allow ModelAdmin.radio_fields to work with NullBooleanField
--------------------------------------+------------------------------------
Reporter: Jerome Leclanche | Owner: Musen
Type: Cleanup/optimization | Status: assigned
Component: contrib.admin | Version: 1.10
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------

Comment (by Tim Graham):

Yes, I think we should try to deprecate `NullBooleanField`. I gave an
update in ticket:23130#comment:20.

--
Ticket URL: <https://code.djangoproject.com/ticket/27917#comment:5>

Django

unread,
Oct 17, 2020, 11:02:33 AM10/17/20
to django-...@googlegroups.com
#27917: Allow ModelAdmin.radio_fields to work with NullBooleanField
--------------------------------------+------------------------------------
Reporter: Jerome Leclanche | Owner: Musen
Type: Cleanup/optimization | Status: closed
Component: contrib.admin | Version: 1.10
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Jacob Walls):

* status: assigned => closed
* resolution: => fixed


Comment:

In d976c254fc76e5f04d81dfd9d142c58e933c9c92 the decision was made to
document providing `choices` to `forms.NullBooleanField` in order to use
`Select` or `RadioSelect` widgets. I believe that also resolves this
issue, since the error message is now appropriate:

{{{


(admin.E023) The value of 'radio_fields' refers to 'foo', which is not an
instance of ForeignKey, and does not have a 'choices' definition.
}}}

See discussion on tickets #23681 and #27445.

--
Ticket URL: <https://code.djangoproject.com/ticket/27917#comment:6>

Reply all
Reply to author
Forward
0 new messages