Micah Pearce
Micah Pearce

Reputation: 1945

Django: inlineformset field with dropdown menu choices

I have a inlineformset that I use to update multiple fields. I'm struggling to get a dropdown menu for my form.

Multiplier= (
    (1,0.25),
    (2,0.5),
    (3,0.75),
    (4,1),
    (5,1.25),
    (6,1.5),
    (7,1.75),
    (8,2),
)

ChildSet = inlineformset_factory(Parent, Child, 
    extra=0,
    widgets={
        'a':forms.ChoiceField(choices=Multiplier),
        'b':forms.TextInput(attrs={'size': '6',}),
        'c':forms.TextInput(attrs={'size': '6',}),
    }

The form likes TextInput, but it doesn't like ChoiceField. Is there a better way to do this?

Upvotes: 1

Views: 342

Answers (1)

solarissmoke
solarissmoke

Reputation: 31434

ChoiceField is not a widget, it is a field that uses the Select widget:

widgets = {
    'a':forms.Select(choices=Multiplier),
    'b':forms.TextInput(attrs={'size': '6',}),
    'c':forms.TextInput(attrs={'size': '6',}),
}

Upvotes: 2

Related Questions