Note that there are some explanatory texts on larger screens.

plurals
  1. PODynamic View not displayed
    primarykey
    data
    text
    <p>I am trying to take a quiz and if you answer a question wrong you see that question get added to a list of wrong questions.</p> <p>Questions can be used in multiple quizes so I can't hard code ask question_1 then question_2 etc.</p> <p>When I load the page I see the first question but then if I submit or refresh I see the right.html template. It doesn't ask all of the questions.</p> <p>It should ask all of the questions before rendering the right.html page</p> <pre><code>for question in quiz.questions.all(): if question not in asked_questions: asked_questions.append(question) return answer_question(request, quiz_id, question.id, module_list) </code></pre> <h1>models.py</h1> <pre><code>class Choice(models.Model): choice = models.CharField(max_length=64) def __unicode__(self): return self.choice #create a multiple choice quiz to start class Question(models.Model): question = models.CharField(max_length=64) answer = models.CharField(max_length=64) choices = models.ManyToManyField(Choice) module = models.CharField(max_length=64) def __unicode__(self): return self.question class Quiz(models.Model): name = models.CharField(max_length=64) questions = models.ManyToManyField(Question) def __unicode__(self): return self.name </code></pre> <h1>views.py</h1> <pre><code>asked_questions = [] module_list = [] module_list.append('test') def take_quiz(request, quiz_id): quiz = Quiz.objects.get(id=str(quiz_id)) for question in quiz.questions.all(): if question not in asked_questions: asked_questions.append(question) return answer_question(request, quiz_id, question.id, module_list) #quiz is over return render (request, 'right.html') def answer_question(request, quiz_id, question_id, module_list): question = Question.objects.get(id=question_id) #module_list = [] if request.method == 'POST': form = QuestionForm(request.POST) choices = [(i, i) for i in question.choices.all()] form.fields['selection'].choices = choices if form.is_valid(): if form.cleaned_data['selection'] != str(question.answer): module_list.append(question.module) return take_quiz(request, quiz_id) else: form = QuestionForm() choices = [(i, i) for i in question.choices.all()] form.fields['selection'].choices = choices return render(request, 'answer_question.html', {'question':question, 'form':form, 'module_list':module_list}) </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload