Opened 4 years ago

Last modified 6 weeks ago

#27704 new New feature

contrib.postgres.ArrayField with choices should use TypedMultipleChoiceField as its default form field class

Reported by: Carl Meyer Owned by:
Component: contrib.postgres Version: master
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: no


Currently the contrib.postgres ArrayField implements no special handling for choices, which makes it pretty useless with choices; you can specify your choices as a list of possible arrays for the ArrayField to contain. This is, I suppose, consistent in some technical sense, but rarely if ever useful in practice. It's very handy to use an ArrayField with choices to implement a multiple-choice field. We already have a TypedMultipleChoiceField form field in Django, so the implementation for this is just a trivial enhancement to the ArrayField.formfield method: if self.choices is set, use TypedMultipleChoiceField as the form class, with the base_field used to determine the expected type.

Any objections to this before I submit a PR for it?

Change History (5)

comment:1 Changed 4 years ago by Claude Paroz

Triage Stage: UnreviewedAccepted


comment:2 Changed 4 years ago by Claude Paroz

See also #27161

comment:3 Changed 4 years ago by Claude Paroz

Has patch: set
Patch needs improvement: set

Here is a preliminary patch. Obviously needs some more work, but it's a start...

comment:4 Changed 3 years ago by Claude Paroz

I've updated the patch and clarified the fact that choices should be defined on the base_field, not on the ArrayField itself. Hopefully it's a sensible recommendation!

comment:5 Changed 6 weeks ago by Gordon Wrigley

It would be nice to get this done, it seems such an obvious little change.

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