for question in questions answer self hand_in answers filter question

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
for question in questions:
answer = self.hand_in.answers.filter(question=question).first()
# INSTEAD OF THIS
# append_forms(question, data=request.POST, instance=answer, request=request)
# WILL BE THIS
form = make_form_for_question(question, data=request.POST, instance=answer, request=request)
question_forms.append(form)
# INSTEAD OF THIS
# Check all questions and make sure they're valid
# if not all([question_valid(question, request) for question in questions]):
# LOGGER.debug("Question validation failed exam event '%s'", self.object.pk)
# return render(request, self.template_name, context)
# WILL BE THIS
if not all([question_form.is_valid() for question_form in question_forms]):
LOGGER.debug("Question validation failed exam event '%s'", self.object.pk)
return render(request, self.template_name, context)
# INSTEAD OF THIS
# Save all questions
# for question in questions:
# question_save(question, self.hand_in)
# WILL BE THIS
for question_form in question_forms:
question_form.save(self.hand_in)
# OR
question_form.save()