Opened 12 years ago

Closed 12 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: no UI/UX: no


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@…> 12 years ago.
queryset as property

Download all attachments as: .zip

Change History (3)

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

queryset as property

comment:1 Changed 12 years ago by miracle2k

Cc: michael@… added

comment:2 Changed 12 years ago by Gary Wilson

Resolution: duplicate
Status: newclosed

dup of #4787.

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