1👍
✅
In Django 1.4 you can override the widgets of a ModelForm
. The modelformset_factory
takes ModelForm
as an argument.
I think you can acheive what you want by defining a model form with the required widgets, then use that model form when creating the formset. No backporting required.
class RegularAvailDateForm(ModelForm):
class Meta:
model = AvailabilitySchedule
fields = ('active','dow', 'hour_start', 'hour_end')
widgets = {
'active' : CheckboxInput(),
'dow': HiddenInput(),
'hour_start': NumberInput(attrs={'min': '0', 'max': '23', 'step': '1'}),
'hour_end': NumberInput(attrs={'min': '1', 'max': '24', 'step': '1'}),
}
FormSet = modelformset_factory(AvailabilitySchedule, RegularAvailDateForm)
The same goes for the second part of your question. Don’t dig deep into the formset code to try and set the label of a model form. Just pass modelformset_factory
a model form that sets the correct labels in its __init__
method.
Source:stackexchange.com