Opened 8 years ago
Closed 4 years ago
#27917 closed Cleanup/optimization (fixed)
Allow ModelAdmin.radio_fields to work with NullBooleanField
Reported by: | Jerome Leclanche | Owned by: | Musen |
---|---|---|---|
Component: | contrib.admin | Version: | 1.10 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
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:
Change History (6)
comment:1 by , 8 years ago
Component: | Uncategorized → contrib.admin |
---|---|
Summary: | ModelAdmin rejects NullBooleanField as a valid radio_fields item → Allow ModelAdmin.radio_fields to work with NullBooleanField |
Type: | Uncategorized → Cleanup/optimization |
comment:2 by , 8 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:3 by , 8 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:4 by , 8 years ago
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.
comment:5 by , 8 years ago
Yes, I think we should try to deprecate NullBooleanField
. I gave an update in ticket:23130#comment:20.
comment:6 by , 4 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
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.
It's not as simple as removing the system check. Changes in
BaseModelAdmin.formfield_for_dbfield
are also required to add support forNullBooleanField
inradio_fields
. Fixing #23130, which deprecatesNullBooleanField
in favor of allowingnull=True
onBooleanField
, may help or even completely solve this issue.