from django.db import models
-from quiz.models import Quiz, Category
+from django_quiz.quiz.models import Quiz, Category
"""
Multiple choice style question for quiz
from django import forms
from django.contrib import admin
from django.contrib.admin.widgets import FilteredSelectMultiple
-from quiz.models import Quiz, Category, Progress
-from multichoice.models import Question, Answer
+from django_quiz.quiz.models import Quiz, Category, Progress
+from django_quiz.multichoice.models import Question, Answer
class QuestionInline(admin.TabularInline):
model = Question.quiz.through
random_order = models.BooleanField(blank=False,
default=False,
- help_text="Display the questions in a random order or as they are set?",
+ help_text="Display the questions in a\
+ random order or as they are set?",
)
answers_at_end = models.BooleanField(blank=False,
default=False,
- help_text="Correct answer is NOT shown after question. Answers displayed at end",
+ help_text="Correct answer is NOT shown\
+ after question. Answers displayed at end",
)
exam_paper = models.BooleanField(blank=False,
default=False,
- help_text="If yes, the result of each attempt by a user will be stored",
+ help_text="If yes, the result of each\
+ attempt by a user will be stored",
)
def save(self, force_insert=False, force_update=False):
- self.url = self.url.replace(' ', '-').lower() # automatically converts url to lowercase, replace space with dash
- self.url = ''.join(letter for letter in self.url if letter.isalnum() or letter == '-') # removes non-alphanumerics
+ self.url = self.url.replace(' ', '-').lower()
+ # automatically converts url to lowercase, replace space with dash
+
+ self.url = ''.join(letter for letter in self.url if letter.isalnum()
+ or letter == '-') # removes non-alphanumerics
+
super(Quiz, self).save(force_insert, force_update)
from django import template
-from multichoice.models import Question, Answer
+from django_quiz.multichoice.models import Question, Answer
register = template.Library()
from django.shortcuts import render, get_object_or_404
-from quiz.models import Quiz, Category, Progress, Sitting
-from multichoice.models import Question, Answer
+from django_quiz.quiz.models import Quiz, Category, Progress, Sitting
+from django_quiz.multichoice.models import Question, Answer
"""
and return the previous questions details
"""
quiz_id = str(quiz.id)
+ question_list = request.session[q_list] # list of ints, each is question id
guess = request.GET['guess']
answer = Answer.objects.get(id=guess)
question = answer.question # the id of the question
--- /dev/null
+from django.db import models
+from django_quiz.quiz.models import Quiz, Category
+
+class TF_Question(models.Model):
+
+ quiz = models.ManyToManyField(Quiz, blank=True, )
+
+ category = models.ForeignKey(Category, blank=True, null=True, )
+
+ content = models.CharField(max_length=1000,
+ blank=False,
+ help_text="Enter the question text that you want displayed",
+ verbose_name='Question',
+ )
+
+ explanation = models.TextField(max_length=2000,
+ blank=True,
+ help_text="Explanation to be shown after the question has been answered.",
+ verbose_name='Explanation',
+ )
+
+ correct = models.BooleanField(blank=False,
+ default=False,
+ help_text="Is this question true or false?"
+ )
+
+ class Meta:
+ verbose_name = "Question"
+ verbose_name_plural = "Questions"
+ ordering = ['category']
+
+
+ def __unicode__(self):
+ return self.content
+
--- /dev/null
+from django.db import models
+
+# Create your models here.
--- /dev/null
+from django.test import TestCase
+
+from django_quiz.true_false.models import TF_Question
+
+
+class TestTrueFalseQuestionModel(TestCase):
+ def setUp(self):
+ TF_Question.objects.create(content = "Is red the best colour?",
+ explanation = "it is",
+ correct = True,)
+ TF_Question.objects.create(content = "Is blue the best colour?",
+ explanation = "it is not",
+ correct = False,)
+
+ def test_true_q(self):
+ red = TF_Question.objects.get(explanation = "it is")
+ self.assertEqual(red.correct, True)
+
+ def test_false_q(self):
+ red = TF_Question.objects.get(explanation = "it is not")
+ self.assertEqual(red.correct, False)
--- /dev/null
+"""
+This file demonstrates writing tests using the unittest module. These will pass
+when you run "manage.py test".
+
+Replace this with more appropriate tests for your application.
+"""
+
+from django.test import TestCase
+
+
+class SimpleTest(TestCase):
+ def test_basic_addition(self):
+ """
+ Tests that 1 + 1 always equals 2.
+ """
+ self.assertEqual(1 + 1, 2)
--- /dev/null
+# Create your views here.