2👍
✅
ModelForms don’t allow you to inherit more than one model class, however, a view is indifferent to the number of form classes it can process. To the end user, you could present two form classes combined in one HTML form. Example, assuming you have two model form classes:
def my_view(request):
keyword_form = KeywordForm(request.POST or None)
another_form = AnotherForm(request.POST or None)
if keyword_form.is_valid and another_form.is_valid():
# do whatever
return render(request, 'your-template.html',
{'keyword_form': keyword_form, 'another_form': another_form})
# your_template.html
<form action="." method="post" enctype="application/x-www-form-urlencoded">
<ul>
{{ keyword_form.as_ul }}
{{ another_form.as_ul }}
</ul>
<button type="submit">Submit</button>
</form>
Of course, if you need exacting control over what fields go where, you can always define your field locations instead of using the quick and dirty rendering. Hope that helps you out.
Source:stackexchange.com