#
from django.db import models
from django.contrib.sites.models import Site
+from django.utils.encoding import python_2_unicode_compatible
from django.utils.translation import ugettext_lazy as _
from django.conf import settings
verbose_name_plural = _('quizzes')
@classmethod
- def current(cls):
- return cls.objects.get(id=settings.SITE_ID)
+ def current(cls, request):
+ return cls.objects.get(domain=request.get_host())
def start(self):
return self.question_set.all()[0]
return self.get_absolute_url()
+@python_2_unicode_compatible
class Result(models.Model):
quiz = models.ForeignKey(Quiz)
slug = models.SlugField(db_index=True)
verbose_name_plural = _('results')
ordering = ['quiz', 'title']
- def __unicode__(self):
+ def __str__(self):
return self.title
@models.permalink
return ('quiz_result', [self.slug])
+@python_2_unicode_compatible
class Question(models.Model):
quiz = models.ForeignKey(Quiz)
slug = models.SlugField(db_index=True)
ordering = ['quiz', 'ordering']
unique_together = [['quiz', 'slug'], ['quiz', 'ordering']]
- def __unicode__(self):
+ def __str__(self):
return self.title
@models.permalink
return self.quiz.where_to()
-
+@python_2_unicode_compatible
class Answer(models.Model):
title = models.CharField(max_length=255)
question = models.ForeignKey(Question)
verbose_name_plural = _('answers')
ordering = ['question', 'ordering']
- def __unicode__(self):
+ def __str__(self):
return self.title
def where_to(self):