- 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.
* 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>
* stage: Unreviewed => Accepted
--
Ticket URL: <https://code.djangoproject.com/ticket/27917#comment:2>
* owner: nobody => Musen
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/27917#comment:3>
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>
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>
* 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>