class StudyRecordDeialView(View):
def get(self, request, class_record_id):
class_record_obj = models.ClassStudyRecord.objects.get(pk=class_record_id)
print(class_record_obj)
all_study_recored = models.StudentStudyRecord.objects.filter(
classstudyrecord=class_record_obj,
)
form_set_obj = modelformset_factory(model=models.StudentStudyRecord,form=StudyRecordDeialModelForm,extra=0)
formset = form_set_obj(queryset=all_study_recored)
return render(request, 'student/study_record_detail.html',{'formset': formset})
def post(self, request, class_record_id):
class_record_obj = models.ClassStudyRecord.objects.get(pk=class_record_id)
all_study_recored = models.StudentStudyRecord.objects.filter(
classstudyrecord=class_record_obj,
)
form_set_obj = modelformset_factory(model=models.StudentStudyRecord, form=StudyRecordDeialModelForm, extra=0)
formset = form_set_obj(request.POST)
if formset.is_valid():
formset.save()
else:
print(formset.errors)
return redirect(reverse('study_decord',args=(class_record_id,)))
{{ formset.management_form }} <!-- 使用modelformset的时候这句话一定要加在前端页面里,固定的昂 -->