Thư viện multi-form-view (class MultiModelFormView) cho phép render và validate nhiều ModelForm cùng lúc trong một template, một nút submit.
Ví dụ
2 model: Student, Teacher.
2 Form: StudentForm, TeacherForm.
View:
class SchoolData(MultiModelFormView): form_classes = {'student_form': StudentForm, 'teacher_form': TeacherForm} template_name = 'home.html' def forms_valid(self, forms): forms['student_form'].save() forms['teacher_form'].save() return super().forms_valid(forms)Template:
{{ forms.student_form.as_p }}{{ forms.teacher_form.as_p }}
Kết quả
Một trang nhập liệu cho cả sinh viên và giáo viên, submit cùng lúc.