Django 2 models 1 form

前端 未结 3 844
轻奢々
轻奢々 2020-12-10 22:12

So, I\'m still a total noob at Django and I was wondering how to do the following:

So lets say that I have something like the below code:

class UserP         


        
3条回答
  •  情歌与酒
    2020-12-10 22:39

    The way I did it was to create a form based on the first model, and then to create a form based on the second model that inherits the first form. Meaning:

    class UserProfileForm(ModelForm): ...

    class UserProfileOtherForm(UserProfileForm): ...

    And pass the UserProfileOtherForm to form template. It worked for me. Not sure if there is a simpler approach.

提交回复
热议问题