quiz/models.py
author nishanth
Thu, 01 Jul 2010 17:05:57 +0530
changeset 86 404e9c1b8cff
parent 82 79ae8288b5ff
child 87 e81b105b1128
permissions -rw-r--r--
now questions are displayed properly in edit_question page. hav to implement the submit and stuff

from django.db import models
from django.contrib.auth.models import User

from offline.event.models import Event

TOPIC_CHOICES = (("11", "Plotting"),
                 ("12", "Lists and Files"),
                 ("13", "For Loops"),
                 ("14", "Strings"),
                 ("15", "Dictionaries and Piecharts"),
                 ("16", "Statistics"),
                 ("17", "Arrays and Matrices"),
                 ("18", "Solving linear equations"),
                 ("19", "Finding roots"),

                 ("21", "Basic Datatypes"),
                 ("22", "Input and Output"),
                 ("23", "Lists and Tuples"),
                 ("24", "Dictionaries"),
                 ("25", "Sets"),
                 ("26", "Conditional Statements"),
                 ("27", "Functions"),
                 )

class Profile(models.Model):
    """ A profile for quiz takers.
    """

    user = models.ForeignKey(User)
    profession = models.CharField(max_length=20,help_text="(Ex: Faculty, Student etc.)")
    affiliated_to = models.CharField(max_length=100, verbose_name="College/Company")

class QuestionBank(models.Model):
    """ A model for holding the database of questions.
    """

    quiz_num = models.CharField(max_length=2, default="00")
    topic = models.CharField(max_length=2,choices=TOPIC_CHOICES)

    description = models.TextField()
    code = models.TextField(blank=True)
    options = models.TextField(blank=True)
    time_limit = models.PositiveSmallIntegerField()
    expected_ans = models.TextField()

    def get_values(self):

        values_dict = {"quiz_num" : self.quiz_num,
                       "topic" : self.topic,
                       "description" : self.description,
                       "code" : self.code,
                       "options" : self.options,
                       "time_limit" : self.time_limit,
                       "expected_ans" : self.expected_ans,
                      }
        return values_dict

    def __unicode__(self):

        return self.description

class Answer(models.Model):
    """ A model for holding answers submitted by users.
    """

    question = models.ForeignKey(QuestionBank, related_name="%(class)s")
    submitted_ans = models.TextField()
    is_correct = models.BooleanField(default=False)

class Quiz(models.Model):
    """ A model to hold the proceeding of a quiz.
    """

    user = models.ForeignKey(User)
    event = models.ForeignKey(Event, related_name="%(class)s")
    user_ip = models.CharField(max_length=15)
    key = models.CharField(max_length=10)
    
    quiz_num = models.CharField(max_length=2)
    que_remaining = models.CharField(max_length=100)
    que_answered = models.ManyToManyField(Answer, related_name="%(class)s")