开发者

inlineformset_factory widget aka field style

I can't get widgets to work when they are used in conjunction with inlineformset_factory

class TravelsRelationsForm(forms.ModelForm):
    def __init__(self, *args, **kwargs):
        super(TravelsRelationsForm, self).__init__(*args, **kwargs)
        self.fields['date_start'].widget.attrs['class'] = 'datetimepicker'

    class Meta:
        model = TravelsRelations
        exclude = ('user',)

TravelFormSet = inlineformset_factory(Trav开发者_开发知识库els, TravelsRelations, exclude=('user',))

I've tried width widget defined under Meta but it doesn't work either... I've searched over the net and neither solution worked... I just want to apply style to the input field.

What am I doing wrong?

Thanks!


Figured it out...

The solution is to add form=MyChildModelForm to the inlineformset_factory...

inlineformset_factory(Parent, Child, form=MyChildModelForm)

And the you define the widget under Meta of the MyChildModelForm as you usually would...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜