Opened 13 years ago

Closed 12 years ago

#17416 closed Bug (fixed)

inlineformset_factory doesn't allow the widgets argument

Reported by: Jacob Owned by: Nick Sandford
Component: Forms Version: dev
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

Description

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 by Łukasz Rekucki, 13 years ago

Triage Stage: UnreviewedAccepted

comment:2 by anonymous, 13 years ago

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

in models.py

class SomeForm(ModelForm):

class Meta:

model = Something
widgets = {

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

in views.py

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

comment:3 by Nick Sandford, 12 years ago

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: https://github.com/django/django/pull/630.

comment:4 by wim@…, 12 years ago

Triage Stage: AcceptedReady for checkin

comment:5 by Claude Paroz <claude@…>, 12 years ago

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