Opened 13 years ago

Closed 9 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)

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

Download all attachments as: .zip

Change History (11)

by Simon Litchfield, 13 years ago

comment:1 by Simon Litchfield, 13 years ago

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

comment:2 by Greg Turner, 13 years ago

Cc: Greg Turner added

comment:3 by Greg Turner, 13 years ago

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 by Greg Turner, 13 years ago

Keywords: sprintdec2010 added

comment:5 by Matthias Kestenholz, 13 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 James Addison, 13 years ago

milestone: 1.3
Severity: Normal
Type: Bug

comment:7 by Aymeric Augustin, 12 years ago

UI/UX: unset

Change UI/UX from NULL to False.

comment:8 by Aymeric Augustin, 12 years ago

Easy pickings: unset

Change Easy pickings from NULL to False.

comment:9 by Tommy Beadle, 9 years ago

Owner: changed from nobody to Tommy Beadle
Status: newassigned

comment:10 by Tommy Beadle, 9 years ago

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