summaryrefslogtreecommitdiff
path: root/yaksh/models.py
diff options
context:
space:
mode:
Diffstat (limited to 'yaksh/models.py')
-rw-r--r--yaksh/models.py11
1 files changed, 6 insertions, 5 deletions
diff --git a/yaksh/models.py b/yaksh/models.py
index 6dc8ce2..de794c4 100644
--- a/yaksh/models.py
+++ b/yaksh/models.py
@@ -1196,11 +1196,12 @@ class AnswerPaper(models.Model):
def get_current_question(self, questions):
if self.questions_order:
- question_id = int(self.questions_order.split(',')[0])
- question = questions.get(id=question_id)
- else:
- question = questions.first()
- return question
+ available_question_ids = questions.values_list('id', flat=True)
+ ordered_question_ids = [int(q) for q in self.questions_order.split(',')]
+ for qid in ordered_question_ids:
+ if qid in available_question_ids:
+ return questions.get(id=qid)
+ return questions.first()
def questions_left(self):
"""Returns the number of questions left."""