Opened 6 years ago

Closed 20 months ago

#14671 closed Bug (wontfix)

Allow overriding of ModelChoiceField.choices

Reported by: Simon Litchfield Owned by: Tommy Beadle
Component: Forms Version: master
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)

modelchoicefield_choices.diff (1.3 KB) - added by Simon Litchfield 6 years ago.

Download all attachments as: .zip

Change History (11)

Changed 6 years ago by Simon Litchfield

comment:1 Changed 6 years ago by Simon Litchfield

Note the patch has also swept up the addition of 'BaseModelFormSet', 'BaseInlineFormSet' to all (they can be useful!)

comment:2 Changed 6 years ago by Greg Turner

Cc: Greg Turner added

comment:3 Changed 6 years ago by Greg Turner

Cc: Greg Turner removed
Needs tests: set
Triage Stage: UnreviewedAccepted

-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 Changed 6 years ago by Greg Turner

Keywords: sprintdec2010 added

comment:5 Changed 6 years ago by Matthias Kestenholz

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 Changed 6 years ago by James Addison

milestone: 1.3
Severity: Normal
Type: Bug

comment:7 Changed 5 years ago by Aymeric Augustin

UI/UX: unset

Change UI/UX from NULL to False.

comment:8 Changed 5 years ago by Aymeric Augustin

Easy pickings: unset

Change Easy pickings from NULL to False.

comment:9 Changed 20 months ago by Tommy Beadle

Owner: changed from nobody to Tommy Beadle
Status: newassigned

comment:10 Changed 20 months ago by Tommy Beadle

Resolution: wontfix
Status: assignedclosed

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: See TracTickets for help on using tickets.
Back to Top