Opened 7 years ago

Closed 6 years ago

#17416 closed Bug (fixed)

inlineformset_factory doesn't allow the widgets argument

Reported by: Jacob Owned by: Nick Sandford
Component: Forms Version: master
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


modelformset_factory supports a widgets argument for specifying custom widgets in the created forms, so I expected inlineformset_factory to do the same. That is, I tried this:

ChoiceFormset = inlineformset_factory(Poll, Choice, widgets = {'order': forms.HiddenInput})

No dice: inlineformset_factory() got an unexpected keyword argument 'widgets'.

I think this is just a simple omission since inlineformset_factory is a thin wrapper over modelformset_factory but I haven't investigated the history to see if this argument was an intentional or unintentional omission.

Change History (5)

comment:1 Changed 7 years ago by Łukasz Rekucki

Triage Stage: UnreviewedAccepted

comment:2 Changed 7 years ago by anonymous

There is a work around for this bug/feature,
1) Create a ModelForm with the requested widget
2) Pass the ModelForm as form argument and voila, the widget works


class SomeForm(ModelForm):

class Meta:

model = Something
widgets = {

'level' : forms.Select(choices=SOME_CHOICES)


SomeFormsetFactory = inlineformset_factory(Parent, Something, form=SomeForm)

comment:3 Changed 6 years ago by Nick Sandford

Has patch: set
Owner: changed from nobody to Nick Sandford
Status: newassigned
Version: 1.3master

Added code, tests and documentation into a similar ticket's (#19569) pull request here:

comment:4 Changed 6 years ago by wim@…

Triage Stage: AcceptedReady for checkin

comment:5 Changed 6 years ago by Claude Paroz <claude@…>

Resolution: fixed
Status: assignedclosed

In 93e79b45bc5288d1ca0eb5b6eade30d3c7110b24:

Fixed #17416 -- Added widgets argument to inlineformset_factory and modelformset_factory

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