I am trying to migrate a custom field renderer in a Django 1.8 form to Django 3.2.
The form looks like this:
class SomeEditForm(forms.ModelForm):
job_uuid=forms.CharField(widget=forms.HiddenInput())
class Meta:
model=Job
fields=('status',)
widgets={'status': forms.RadioSelect(renderer=BSRadioFieldRenderer)}
So as it seems there is no Rendermixin anymore which accepts a renderer in its def init(). I have read the new source code and see that RadioSelect is now a subclass of ChoiceWidget. I cant get my head around to inject my old renderer into the new structure.
Can someone please point me into the right direction?
Thanks for your help! :)
There seems to be a hacky way which works... Just subclass forms.RadioSelect and accept the renderer kwarg like this:
class CustomRadioSelect(forms.RadioSelect):
def __init__(self, renderer=None, *args, **kwargs):
super(forms.RadioSelect, self).__init__(*args, **kwargs)
class SomeEditForm(forms.ModelForm):
job_uuid=forms.CharField(widget=forms.HiddenInput())
class Meta:
model=Job
fields=('status',)
widgets = {'status': CustomRadioSelect(renderer=BSRadioFieldRenderer)}
Please note that these classes are truncated and I only wrote those parts in here which are relevant to the problem I had.