Opened 7 years ago

Last modified 19 months ago

#27704 assigned New feature

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

Reported by: Carl Meyer Owned by: Anvesh Mishra
Component: contrib.postgres Version: dev
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

Description

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

comment:1 by Claude Paroz, 7 years ago

Triage Stage: UnreviewedAccepted

Please!

comment:2 by Claude Paroz, 7 years ago

See also #27161

comment:3 by Claude Paroz, 7 years ago

Has patch: set
Patch needs improvement: set

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

comment:4 by Claude Paroz, 7 years ago

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 by Gordon Wrigley, 4 years ago

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

comment:6 by Anvesh Mishra, 2 years ago

Owner: set to Anvesh Mishra
Status: newassigned

comment:7 by Anvesh Mishra, 23 months ago

Submitted a patch.

comment:8 by Mariusz Felisiak, 23 months ago

Patch needs improvement: unset

comment:9 by Mariusz Felisiak, 23 months ago

Patch needs improvement: set

in reply to:  9 comment:10 by Anvesh Mishra, 19 months ago

Replying to Mariusz Felisiak:

Per Nick's review.

Can we have a review over this?

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