Code

Opened 6 years ago

Closed 6 years ago

Last modified 3 years ago

#8346 closed (duplicate)

overriding widget in ModelChoiceField doesn't work as expected

Reported by: derelm Owned by: nobody
Component: Forms Version: master
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)

simple_replacement_of_widgets.diff (1.7 KB) - added by oyvind 6 years ago.
should fix this issue

Download all attachments as: .zip

Change History (4)

Changed 6 years ago by oyvind

should fix this issue

comment:1 Changed 6 years ago by Alex

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

comment:2 Changed 6 years ago by cgrady

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

comment:3 Changed 3 years ago by jacob

  • milestone 1.0 deleted

Milestone 1.0 deleted

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.