Opened 5 years ago

Closed 7 months ago

#14671 closed Bug (wontfix)

Allow overriding of ModelChoiceField.choices

Reported by: simon29 Owned by: tbeadle
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


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 simon29 5 years ago.

Download all attachments as: .zip

Change History (11)

Changed 5 years ago by simon29

comment:1 Changed 5 years ago by simon29

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

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

comment:2 Changed 5 years ago by cogat

  • Cc cogat added

comment:3 Changed 5 years ago by cogat

  • Cc cogat removed
  • Needs tests set
  • Triage Stage changed from Unreviewed to 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 Changed 5 years ago by cogat

  • Keywords sprintdec2010 added

comment:5 Changed 5 years ago by mk

  • 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 5 years ago by jaddison

  • milestone 1.3 deleted
  • Severity set to Normal
  • Type set to Bug

comment:7 Changed 4 years ago by aaugustin

  • UI/UX unset

Change UI/UX from NULL to False.

comment:8 Changed 4 years ago by aaugustin

  • Easy pickings unset

Change Easy pickings from NULL to False.

comment:9 Changed 7 months ago by tbeadle

  • Owner changed from nobody to tbeadle
  • Status changed from new to assigned

comment:10 Changed 7 months ago by tbeadle

  • Resolution set to wontfix
  • Status changed from assigned to 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 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