Opened 8 years ago
Last modified 2 years 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 , 8 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:3 by , 8 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 , 8 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 , 4 years ago
It would be nice to get this done, it seems such an obvious little change.
comment:6 by , 2 years ago
Owner: | set to |
---|---|
Status: | new → assigned |
comment:8 by , 2 years ago
Patch needs improvement: | unset |
---|
Please!