Code

Opened 2 years ago

Closed 15 months ago

#17416 closed Bug (fixed)

inlineformset_factory doesn't allow the widgets argument

Reported by: jacob Owned by: slurms
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

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.

Attachments (0)

Change History (5)

comment:1 Changed 2 years ago by lrekucki

  • Triage Stage changed from Unreviewed to Accepted

comment:2 Changed 2 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

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 Changed 15 months ago by slurms

  • Has patch set
  • Owner changed from nobody to slurms
  • Status changed from new to assigned
  • Version changed from 1.3 to master

Added code, tests and documentation into a similar ticket's (#19569) pull request here: https://github.com/django/django/pull/630.

comment:4 Changed 15 months ago by wim@…

  • Triage Stage changed from Accepted to Ready for checkin

comment:5 Changed 15 months ago by Claude Paroz <claude@…>

  • Resolution set to fixed
  • Status changed from assigned to closed

In 93e79b45bc5288d1ca0eb5b6eade30d3c7110b24:

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

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.