I am trying to build a simple single page quiz model, with multiple
questions with three classes for quiz,questions and answers, and fourth (not
included) to manage the scores as given below.
class Quiz(models.Model):
name = models.CharField(maxlength=200)
pub_date = models.DateTimeField()
quizmaster = models.ForeignKey(User)
slug = models.SlugField(editable=False)
class Question (models.Model):
quiz = models.ForeignKey(Quiz)
question = models.CharField(maxlength = 300)
answer_explanation = models.TextField()
level = models.CharField(maxlength = 32, choices=levels)
class Choice (models.Model):
question = models.ForeignKey(Question, edit_inline=models.TABULAR,
num_in_admin=5)
answer = models.CharField (maxlength=200, core = True)
is_rightanswer = models.BooleanField()
My question is in Views, how do I display all questions in a single page and
then of course accept the answers, display the right ones, and indicate the
wrong ones and so on.
Since I followed the polls tutorial I managed to display the different
quizzes with the following view
def index(request):
latest_quiz_list = Quiz.objects.all().order_by('-pub_date')[:5]
return render_to_response('quiz1/index.html', {'latest_quiz_list':
latest_quiz_list}, )
However I am unable to display the answers to the different questions.
My detail function in views.py look like this
def detail(request, slug):
p=Quiz.objects.get(slug=slug)
q=Question.objects.filter(quiz=p)
return render_to_response('quiz1/detail.html', {'quiz': p, 'questions':q
} )
Problem is the {% for loop does not accept choices.
{% for choice in questions.choice.all %}
{{ choice.answer }}
<input type="radio" name="choice" id="choice{{ forloop.counter }}"
value="{{ choice.answer }} " />
<label for="{{ choice.answer }} {{ forloop.counter }}">{{
choice.answer}}</label><br />
{% endfor %}
{% endfor %}
I have used the above template in the loop and it does not work.
I know I need to somehow chain each choice to the right question, but I am
unable to.
Thanks in advance
K Mallory
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---