Django: How to change a field widget in a Inline Formset

后端 未结 4 1733
深忆病人
深忆病人 2021-02-13 07:21

I am new to Django and I think I am missing this in the docs.
The problem is that in inline-formset I dont declare a form, just pass two models to construct it.
I want

4条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-13 07:42

    you can subclass the formset and override the add_fields method. This worked for me and I am using Django 1.5 :( .

    AuthorInlineFormSet = inlineformset_factory(Author, Book)
    class AuthorFormSet(AuthorInlineFormSet):
            def add_fields(self, form, index):
                super(ReferenceForm,self).add_fields(form,index)
                form.fields["name"] = forms.CharField(widget=forms.TextInput())
    

提交回复
热议问题