Skip to content

Instantly share code, notes, and snippets.

@viruthagiri
Created October 3, 2014 14:42
Show Gist options
  • Select an option

  • Save viruthagiri/1c49054e25cd3317d9ec to your computer and use it in GitHub Desktop.

Select an option

Save viruthagiri/1c49054e25cd3317d9ec to your computer and use it in GitHub Desktop.
class Product(models.Model):
name = models.CharField(max_length=256, unique=True)
def __unicode__(self):
return self.name
class Topic(models.Model):
name = models.CharField(max_length=256)
product = models.ForeignKey('Product', related_name='topics')
class Meta:
unique_together = ("name", "product")
def __unicode__(self):
return self.name
class Module(models.Model):
name = models.CharField(max_length=256, unique=True)
threshold = models.IntegerField()
topic = models.ForeignKey('Topic', related_name='modules')
def __unicode__(self):
return self.name
class Choice(models.Model):
question = models.ForeignKey('Question', related_name='choices')
choice = models.CharField(max_length=255)
order = models.IntegerField(default=0)
count = models.IntegerField(default=0, editable=False)
is_correct = models.BooleanField(default=False)
def __unicode__(self):
return self.choice
#multiple choice question
class Question(models.Model):
quiz = models.ForeignKey('Quiz', related_name='questions')
question = models.CharField(max_length=64)
module = models.ForeignKey('Module', related_name='questions')
times_correct = models.IntegerField(editable=False, default=0)
times_total = models.IntegerField(editable=False, default=0)
def _get_average(self):
"Returns the average in percent"
if self.times_total != 0:
return (self.times_correct / float(self.times_total))*100
return 0.0
average = property(_get_average)
def __unicode__(self):
return self.question
class Quiz(models.Model):
#id = models.UUIDField(primary_key=True)
name = models.CharField(max_length=64)
#questions = models.ManyToManyField(Question)
created_by = models.ForeignKey(settings.AUTH_USER_MODEL, related_name="quizzes")
#questions = models.ManyToManyField(QuestionManager, null=True, related_name="quiz")
class Meta:
verbose_name_plural = "quizzes"
def __unicode__(self):
return self.name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment