Opened 8 years ago

Closed 8 years ago

#5830 closed (duplicate)

ModelChoiceField does not allow you to change the queryset on the widget after __init__ is called

Reported by: Øyvind Saltvik <oyvind@…> Owned by: nobody
Component: Uncategorized Version: newforms-admin
Severity: Keywords: modelchoicefield property
Cc: michael@… Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


ModelChoiceField.__init__ assigns the default queryset to self.widget.choices; then if you change field.queryset later it is too late, as it does not set self.widget.choices again.

This is easily done by making self.queryset a property()

Attachments (1)

modelchoicefield_queryset_as_property.diff (1.2 KB) - added by Øyvind Saltvik <oyvind@…> 8 years ago.
queryset as property

Download all attachments as: .zip

Change History (3)

Changed 8 years ago by Øyvind Saltvik <oyvind@…>

queryset as property

comment:1 Changed 8 years ago by miracle2k

  • Cc michael@… added
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

comment:2 Changed 8 years ago by gwilson

  • Resolution set to duplicate
  • Status changed from new to closed

dup of #4787.

Note: See TracTickets for help on using tickets.
Back to Top