quiz/models.py
author nishanth
Thu, 01 Jul 2010 16:44:17 +0530
changeset 84 08af9e4ada78
parent 82 79ae8288b5ff
child 86 404e9c1b8cff
permissions -rw-r--r--
modified the link in templates to the correct one and fixed a typo in view
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12
81cd0140a0f2 created the register user functionality.
nishanth
parents:
diff changeset
     1
from django.db import models
81cd0140a0f2 created the register user functionality.
nishanth
parents:
diff changeset
     2
from django.contrib.auth.models import User
81cd0140a0f2 created the register user functionality.
nishanth
parents:
diff changeset
     3
81cd0140a0f2 created the register user functionality.
nishanth
parents:
diff changeset
     4
from offline.event.models import Event
81cd0140a0f2 created the register user functionality.
nishanth
parents:
diff changeset
     5
57
0ca5016cde82 added another field to the question_bank model and hence the choices related to that model
nishanth
parents: 43
diff changeset
     6
TOPIC_CHOICES = (("11", "Plotting"),
0ca5016cde82 added another field to the question_bank model and hence the choices related to that model
nishanth
parents: 43
diff changeset
     7
                 ("12", "Lists and Files"),
59
0b57494e8b4e added the field topic to each question in xml file
nishanth
parents: 57
diff changeset
     8
                 ("13", "For Loops"),
0b57494e8b4e added the field topic to each question in xml file
nishanth
parents: 57
diff changeset
     9
                 ("14", "Strings"),
0b57494e8b4e added the field topic to each question in xml file
nishanth
parents: 57
diff changeset
    10
                 ("15", "Dictionaries and Piecharts"),
0b57494e8b4e added the field topic to each question in xml file
nishanth
parents: 57
diff changeset
    11
                 ("16", "Statistics"),
0b57494e8b4e added the field topic to each question in xml file
nishanth
parents: 57
diff changeset
    12
                 ("17", "Arrays and Matrices"),
0b57494e8b4e added the field topic to each question in xml file
nishanth
parents: 57
diff changeset
    13
                 ("18", "Solving linear equations"),
0b57494e8b4e added the field topic to each question in xml file
nishanth
parents: 57
diff changeset
    14
                 ("19", "Finding roots"),
57
0ca5016cde82 added another field to the question_bank model and hence the choices related to that model
nishanth
parents: 43
diff changeset
    15
0ca5016cde82 added another field to the question_bank model and hence the choices related to that model
nishanth
parents: 43
diff changeset
    16
                 ("21", "Basic Datatypes"),
0ca5016cde82 added another field to the question_bank model and hence the choices related to that model
nishanth
parents: 43
diff changeset
    17
                 ("22", "Input and Output"),
0ca5016cde82 added another field to the question_bank model and hence the choices related to that model
nishanth
parents: 43
diff changeset
    18
                 ("23", "Lists and Tuples"),
0ca5016cde82 added another field to the question_bank model and hence the choices related to that model
nishanth
parents: 43
diff changeset
    19
                 ("24", "Dictionaries"),
0ca5016cde82 added another field to the question_bank model and hence the choices related to that model
nishanth
parents: 43
diff changeset
    20
                 ("25", "Sets"),
0ca5016cde82 added another field to the question_bank model and hence the choices related to that model
nishanth
parents: 43
diff changeset
    21
                 ("26", "Conditional Statements"),
0ca5016cde82 added another field to the question_bank model and hence the choices related to that model
nishanth
parents: 43
diff changeset
    22
                 ("27", "Functions"),
0ca5016cde82 added another field to the question_bank model and hence the choices related to that model
nishanth
parents: 43
diff changeset
    23
                 )
0ca5016cde82 added another field to the question_bank model and hence the choices related to that model
nishanth
parents: 43
diff changeset
    24
12
81cd0140a0f2 created the register user functionality.
nishanth
parents:
diff changeset
    25
class Profile(models.Model):
28
456b7b9e3d13 created a question bank xml file and created a seed_que command for adding questions to db from xml
nishanth
parents: 23
diff changeset
    26
    """ A profile for quiz takers.
456b7b9e3d13 created a question bank xml file and created a seed_que command for adding questions to db from xml
nishanth
parents: 23
diff changeset
    27
    """
12
81cd0140a0f2 created the register user functionality.
nishanth
parents:
diff changeset
    28
81cd0140a0f2 created the register user functionality.
nishanth
parents:
diff changeset
    29
    user = models.ForeignKey(User)
15
99af908a4174 added questions thro seed_db
nishanth
parents: 14
diff changeset
    30
    profession = models.CharField(max_length=20,help_text="(Ex: Faculty, Student etc.)")
12
81cd0140a0f2 created the register user functionality.
nishanth
parents:
diff changeset
    31
    affiliated_to = models.CharField(max_length=100, verbose_name="College/Company")
81cd0140a0f2 created the register user functionality.
nishanth
parents:
diff changeset
    32
81cd0140a0f2 created the register user functionality.
nishanth
parents:
diff changeset
    33
class QuestionBank(models.Model):
81cd0140a0f2 created the register user functionality.
nishanth
parents:
diff changeset
    34
    """ A model for holding the database of questions.
81cd0140a0f2 created the register user functionality.
nishanth
parents:
diff changeset
    35
    """
81cd0140a0f2 created the register user functionality.
nishanth
parents:
diff changeset
    36
57
0ca5016cde82 added another field to the question_bank model and hence the choices related to that model
nishanth
parents: 43
diff changeset
    37
    quiz_num = models.CharField(max_length=2, default="00")
0ca5016cde82 added another field to the question_bank model and hence the choices related to that model
nishanth
parents: 43
diff changeset
    38
    topic = models.CharField(max_length=2,choices=TOPIC_CHOICES)
12
81cd0140a0f2 created the register user functionality.
nishanth
parents:
diff changeset
    39
81cd0140a0f2 created the register user functionality.
nishanth
parents:
diff changeset
    40
    description = models.TextField()
82
79ae8288b5ff removed the restriction on code field and options field in models
nishanth
parents: 64
diff changeset
    41
    code = models.TextField(blank=True)
79ae8288b5ff removed the restriction on code field and options field in models
nishanth
parents: 64
diff changeset
    42
    options = models.TextField(blank=True)
12
81cd0140a0f2 created the register user functionality.
nishanth
parents:
diff changeset
    43
    time_limit = models.PositiveSmallIntegerField()
81cd0140a0f2 created the register user functionality.
nishanth
parents:
diff changeset
    44
    expected_ans = models.TextField()
81cd0140a0f2 created the register user functionality.
nishanth
parents:
diff changeset
    45
64
ba80a1b3b187 now questions are displayed by their description
nishanth
parents: 59
diff changeset
    46
    def __unicode__(self):
ba80a1b3b187 now questions are displayed by their description
nishanth
parents: 59
diff changeset
    47
ba80a1b3b187 now questions are displayed by their description
nishanth
parents: 59
diff changeset
    48
        return self.description
ba80a1b3b187 now questions are displayed by their description
nishanth
parents: 59
diff changeset
    49
12
81cd0140a0f2 created the register user functionality.
nishanth
parents:
diff changeset
    50
class Answer(models.Model):
81cd0140a0f2 created the register user functionality.
nishanth
parents:
diff changeset
    51
    """ A model for holding answers submitted by users.
81cd0140a0f2 created the register user functionality.
nishanth
parents:
diff changeset
    52
    """
81cd0140a0f2 created the register user functionality.
nishanth
parents:
diff changeset
    53
43
265ed367e8cc renamed related_name fields appropriately
nishanth
parents: 39
diff changeset
    54
    question = models.ForeignKey(QuestionBank, related_name="%(class)s")
12
81cd0140a0f2 created the register user functionality.
nishanth
parents:
diff changeset
    55
    submitted_ans = models.TextField()
39
0fa055b8ea98 implemented correct_quiz function and added it at the time of closing quiz and modified question bank
nishanth
parents: 28
diff changeset
    56
    is_correct = models.BooleanField(default=False)
12
81cd0140a0f2 created the register user functionality.
nishanth
parents:
diff changeset
    57
81cd0140a0f2 created the register user functionality.
nishanth
parents:
diff changeset
    58
class Quiz(models.Model):
81cd0140a0f2 created the register user functionality.
nishanth
parents:
diff changeset
    59
    """ A model to hold the proceeding of a quiz.
81cd0140a0f2 created the register user functionality.
nishanth
parents:
diff changeset
    60
    """
81cd0140a0f2 created the register user functionality.
nishanth
parents:
diff changeset
    61
81cd0140a0f2 created the register user functionality.
nishanth
parents:
diff changeset
    62
    user = models.ForeignKey(User)
23
f57c30096b51 added the link on home to attempt quiz
nishanth
parents: 22
diff changeset
    63
    event = models.ForeignKey(Event, related_name="%(class)s")
13
ad193c5014b2 added ip field to model and used it in start page
nishanth
parents: 12
diff changeset
    64
    user_ip = models.CharField(max_length=15)
16
ad51f38d0339 implemented the start quiz functionality
nishanth
parents: 15
diff changeset
    65
    key = models.CharField(max_length=10)
12
81cd0140a0f2 created the register user functionality.
nishanth
parents:
diff changeset
    66
    
81cd0140a0f2 created the register user functionality.
nishanth
parents:
diff changeset
    67
    quiz_num = models.CharField(max_length=2)
81cd0140a0f2 created the register user functionality.
nishanth
parents:
diff changeset
    68
    que_remaining = models.CharField(max_length=100)
43
265ed367e8cc renamed related_name fields appropriately
nishanth
parents: 39
diff changeset
    69
    que_answered = models.ManyToManyField(Answer, related_name="%(class)s")
15
99af908a4174 added questions thro seed_db
nishanth
parents: 14
diff changeset
    70