Inline formset in Django - removing certain fields

前端 未结 3 974
暖寄归人
暖寄归人 2021-01-31 23:10

I need to create an inline formset which

a) excludes some fields from MyModel being displayed altogether

b) displays some some fields MyMode

3条回答
  •  逝去的感伤
    2021-01-31 23:30

    One thing that doesn't seem to be said in the documentation is that you can include a form inside your parameters for model formsets. So, for instance, let's say you have a person modelform, you can use it in a model formset by doing this

    PersonFormSet = inlineformset_factory(User, Person, form=PersonForm, extra=6)
    

    This allows you to do all the form validation, excludes, etc on a modelform level and have the factory replicate it.

提交回复
热议问题