Opened 7 months ago

Last modified 5 months ago

#27917 assigned Cleanup/optimization

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 (5)

comment:1 Changed 7 months ago by Tim Graham

Component: Uncategorizedcontrib.admin
Summary: ModelAdmin rejects NullBooleanField as a valid radio_fields itemAllow ModelAdmin.radio_fields to work with NullBooleanField
Type: UncategorizedCleanup/optimization

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.

comment:2 Changed 7 months ago by Tim Graham

Triage Stage: UnreviewedAccepted

comment:3 Changed 6 months ago by Musen

Owner: changed from nobody to Musen
Status: newassigned

comment:4 Changed 5 months ago 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.

comment:5 Changed 5 months ago by Tim Graham

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

Note: See TracTickets for help on using tickets.
Back to Top