from django.db import models
-from django_quiz.quiz.models import Quiz, Category
+from quiz.models import Quiz, Category
"""
Multiple choice style question for quiz
class 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,
+
+ 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',
)
-
-
+
+
class Meta:
verbose_name = "Question"
verbose_name_plural = "Questions"
def __unicode__(self):
return self.content
-
+
class Answer(models.Model):
question = models.ForeignKey(Question)
-
- content = models.CharField(max_length=1000,
- blank=False,
+
+ content = models.CharField(max_length=1000,
+ blank=False,
help_text="Enter the answer text that you want displayed",
)
-
- correct = models.BooleanField(blank=False,
+
+ correct = models.BooleanField(blank=False,
default=False,
help_text="Is this a correct answer?"
)
-
+
def __unicode__(self):
return self.content
from django import forms
from django.contrib import admin
from django.contrib.admin.widgets import FilteredSelectMultiple
-from django_quiz.quiz.models import Quiz, Category, Progress
-from django_quiz.multichoice.models import Question, Answer
+from quiz.models import Quiz, Category, Progress
+from multichoice.models import Question, Answer
class QuestionInline(admin.TabularInline):
model = Question.quiz.through
class AnswerInline(admin.TabularInline):
- model = Answer
+ model = Answer
"""
-below is from
+below is from
http://stackoverflow.com/questions/11657682/django-admin-interface-using-horizontal-filter-with-inline-manytomany-field
"""
class QuizAdminForm(forms.ModelForm):
class Meta:
model = Quiz
-
+
questions = forms.ModelMultipleChoiceField(
queryset=Question.objects.all(),
required=False,
is_stacked=False
)
)
-
+
def __init__(self, *args, **kwargs):
super(QuizAdminForm, self).__init__(*args, **kwargs)
if self.instance.pk:
self.fields['questions'].initial = self.instance.question_set.all()
-
+
def save(self, commit=True):
quiz = super(QuizAdminForm, self).save(commit=False)
if commit:
class QuizAdmin(admin.ModelAdmin):
form = QuizAdminForm
-
+
list_display = ('title', 'category', )
list_filter = ('category',)
search_fields = ('description', 'category', )
-
-
+
+
class CategoryAdmin(admin.ModelAdmin):
search_fields = ('category', )
list_display = ('content', 'category', )
list_filter = ('category',)
fields = ('content', 'category', 'quiz', 'explanation' )
-
+
search_fields = ('content', )
filter_horizontal = ('quiz',)
-
+
inlines = [AnswerInline]
-
-
+
+
class ProgressAdmin(admin.ModelAdmin):
"""
to do: