diff options
author | Prabhu Ramachandran | 2011-11-09 03:05:03 +0530 |
---|---|---|
committer | Prabhu Ramachandran | 2011-11-09 03:05:03 +0530 |
commit | 6cf7eb9f1a69f596ea0dcc418c1b90d3fb8ec513 (patch) | |
tree | de2f47ad2dd6d7f7f1d26ecb33e3f210a96371cc /exam/models.py | |
parent | 4694d217dd7d5659afdad7ba5937adb85c15371c (diff) | |
download | online_test-6cf7eb9f1a69f596ea0dcc418c1b90d3fb8ec513.tar.gz online_test-6cf7eb9f1a69f596ea0dcc418c1b90d3fb8ec513.tar.bz2 online_test-6cf7eb9f1a69f596ea0dcc418c1b90d3fb8ec513.zip |
ENH: Saving answers and added quit page/button.
Cleaned up the models so the answers submitted are all saved. Also
added a quit button to each question page so a user can easily quit the
exam in order that another may start.
Diffstat (limited to 'exam/models.py')
-rw-r--r-- | exam/models.py | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/exam/models.py b/exam/models.py index 3a8121b..226146a 100644 --- a/exam/models.py +++ b/exam/models.py @@ -1,13 +1,13 @@ from django.db import models from django.contrib.auth.models import User -# Create your models here. class Profile(models.Model): - """Profile for a user to store roll number etc.""" + """Profile for a user to store roll number and other details.""" user = models.ForeignKey(User) roll_number = models.CharField(max_length=20) + class Question(models.Model): """A question in the database.""" # An optional one-line summary of the question. @@ -16,7 +16,7 @@ class Question(models.Model): description = models.TextField() # Number of points for the question. - points = models.IntegerField() + points = models.IntegerField(default=1) # Test cases for the question in the form of code that is run. # This is simple Python code. @@ -24,33 +24,42 @@ class Question(models.Model): def __unicode__(self): return self.summary - + class Answer(models.Model): """Answers submitted by users. """ + # The question for which we are an answer. question = models.ForeignKey(Question) + # The last answer submitted by the user. answer = models.TextField() - attempts = models.IntegerField() - - # Is the question correct. - correct = models.BooleanField() - # Marks obtained. - marks = models.IntegerField() + # Is the answer correct. + correct = models.BooleanField(default=False) + def __unicode__(self): return self.answer + class Quiz(models.Model): """A quiz for a student. """ + # The user taking this quiz. user = models.ForeignKey(User) + # User's IP which is logged. user_ip = models.CharField(max_length=15) + # Unused currently. key = models.CharField(max_length=10) + + # The questions (a list of ids separated by '|') questions = models.CharField(max_length=128) + # The questions successfully answered (a list of ids separated by '|') questions_answered = models.CharField(max_length=128) + # All the submitted answers. + answers = models.ManyToManyField(Answer) + def current_question(self): """Returns the current active question to display.""" qs = self.questions.split('|') |