Opened 14 years ago
Closed 10 years ago
#14671 closed Bug (wontfix)
Allow overriding of ModelChoiceField.choices
Reported by: | Simon Litchfield | Owned by: | Tommy Beadle |
---|---|---|---|
Component: | Forms | Version: | dev |
Severity: | Normal | Keywords: | sprintdec2010 |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | yes |
Needs tests: | yes | Patch needs improvement: | yes |
Easy pickings: | no | UI/UX: | no |
Description
This patch fixes a validation bug when attempting to override choices manually on a ModelChoiceField. Comments in code suggest this should be able to be done.
Note, this used to work until the recent model/form validation changes.
Attachments (1)
Change History (11)
by , 14 years ago
Attachment: | modelchoicefield_choices.diff added |
---|
comment:1 by , 14 years ago
comment:2 by , 14 years ago
Cc: | added |
---|
comment:3 by , 14 years ago
Cc: | removed |
---|---|
Needs tests: | set |
Triage Stage: | Unreviewed → Accepted |
-1 on the addition of BaseModelFormSet to __all__
. Although the classes can be useful, they are abstract, and can be imported explicitly with:
from forms.models import BaseModelFormSet
For the problem at hand, a test that illustrates the bug would help immensely. Reviewing the patch, it looks reasonable, except the choice of variable name for pk
, given that something else could be in self.to_field_name
.
comment:4 by , 14 years ago
Keywords: | sprintdec2010 added |
---|
comment:5 by , 14 years ago
Needs documentation: | set |
---|---|
Patch needs improvement: | set |
The patch needs documentation, tests and reasons why BaseModelFormSet and BaseInlineFormset should be added to all.
comment:6 by , 14 years ago
milestone: | 1.3 |
---|---|
Severity: | → Normal |
Type: | → Bug |
comment:9 by , 10 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:10 by , 10 years ago
Resolution: | → wontfix |
---|---|
Status: | assigned → closed |
I can't think of a use case where it makes sense to add abitrary choices to the ones available for a ModelChoiceField via its queryset. See http://stackoverflow.com/questions/5281195/forms-modelchoicefield-queryset-extra-choice-fields-django-forms for a way to use a normal ChoiceField to accomplish this.
If the desire is to change the appearance of the choices when they are rendered, there is the ModelChoiceField.label_from_instance
method that can be overridden.
Note the patch has also swept up the addition of 'BaseModelFormSet', 'BaseInlineFormSet' to all (they can be useful!)