#8346 closed (duplicate)
overriding widget in ModelChoiceField doesn't work as expected
| Reported by: | derelm | Owned by: | nobody |
|---|---|---|---|
| Component: | Forms | Version: | dev |
| Severity: | Keywords: | ||
| Cc: | Triage Stage: | Accepted | |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | UI/UX: |
Description
Using below custom ModelChoiceField will not use RadioSelect widget as expected.
class MyModelChoiceField(forms.ModelChoiceField):
widget = forms.RadioSelect
You can work around that issue by overriding init like so:
class MyModelChoiceField(forms.ModelChoiceField):
def __init__(self, *args, **kwargs):
return super(MyModelChoiceField, self).__init__(widget=forms.RadioSelect, *args, **kwargs)
I guess this is a bug either with ModelChoiceField or with the documentation.
Attachments (1)
Change History (4)
by , 17 years ago
| Attachment: | simple_replacement_of_widgets.diff added |
|---|
comment:1 by , 17 years ago
| Triage Stage: | Unreviewed → Accepted |
|---|
Note:
See TracTickets
for help on using tickets.
should fix this issue