Django - ModelForm Dynamic field update

后端 未结 4 857
情书的邮戳
情书的邮戳 2021-01-06 11:50

I\'m trying to update certain fields a ModelForm, these fields are not fixed. (I have only tutor that is autopopulated by the view)

Model:



        
4条回答
  •  一个人的身影
    2021-01-06 12:44

    Your question suggests that you have a requirement that uses same model but different fields are hidden in your ModelForm, based on your needs.

    If I understand your question, then you need to Create two different ModelForm based class, both these classes have same model value inside the Meta class. Exclude and include the fields you need. So now you have different ModelForm classes which you can call inside your view logic.

    With this you will have two different forms that depend on same model, with different default fields.

    With clever url and view design you will be able to use the above idea to serve multiple forms from same model.

提交回复
热议问题