diff options
author | mahesh | 2017-09-01 18:13:58 +0530 |
---|---|---|
committer | mahesh | 2017-09-01 18:13:58 +0530 |
commit | 413066da15825ae37c15134536102ada3988e9a6 (patch) | |
tree | 50d55053793da290d395310505af7ddcfe0e5822 /yaksh/models.py | |
parent | ef1e14e19f8bf0c1f075253a71ead98742b3f4d8 (diff) | |
parent | 97a96d1678cb55b95ed14eb9a2b2790415d30abc (diff) | |
download | online_test-413066da15825ae37c15134536102ada3988e9a6.tar.gz online_test-413066da15825ae37c15134536102ada3988e9a6.tar.bz2 online_test-413066da15825ae37c15134536102ada3988e9a6.zip |
Rebase changes
Diffstat (limited to 'yaksh/models.py')
-rw-r--r-- | yaksh/models.py | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/yaksh/models.py b/yaksh/models.py index 56cced8..063e1e3 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -855,13 +855,12 @@ class QuestionPaper(models.Model): def make_answerpaper(self, user, ip, attempt_num): """Creates an answer paper for the user to attempt the quiz""" - ans_paper = AnswerPaper.objects.filter(user=user, - attempt_number=attempt_num, - question_paper=self - ).order_by('-id') - if ans_paper: - ans_paper = ans_paper[0] - else: + try: + ans_paper = AnswerPaper.objects.get(user=user, + attempt_number=attempt_num, + question_paper=self + ) + except AnswerPaper.DoesNotExist: ans_paper = AnswerPaper( user=user, user_ip=ip, @@ -877,6 +876,13 @@ class QuestionPaper(models.Model): ans_paper.questions.add(question) for question in questions: ans_paper.questions_unanswered.add(question) + except AnswerPaper.MultipleObjectsReturned: + ans_paper = AnswerPaper.objects.get(user=user, + attempt_number=attempt_num, + question_paper=self + ).order_by('-id') + ans_paper = ans_paper[0] + return ans_paper def _is_questionpaper_passed(self, user): |