title: How to compare user input to corresponding model field django
body: <p>I'm trying to make learning app for myself and part of my plan is to make a quiz module.</p>
  
  <p>My problem is, that I don't know how to compare user answer with the correct answer that's stored in the model.</p>
  
  <p>Now, the only thing I've tried (except reading docs and stack overflow) was to inject the related model question inside of my HTML to later use in views.py, but from the beginning I felt like that's not the way it should work, so I guess I have to reorganize my models/forms or inside of views.py there is some way to query database for that specific model instance that I don't know.</p>
  
  <p>Here is my code</p>
  
  <p>Models:</p>
  
  <pre><code>class Question(models.Model):
          question = models.CharField(max_length=100, unique=True)
          answer = models.CharField(max_length=100, unique=False)
  
      def __str__(self):
          return self.question
  </code></pre>
  
  <p>Forms:</p>
  
  <pre><code>class Answer(forms.Form):
      answer = forms.CharField()
  </code></pre>
  
  <p>Views:</p>
  
  <pre><code>def quiz(request):
      questions = Question.objects.order_by('question')
      form = Answer()
      context_dict = {'form':form,'questions':questions}
      if request.method == 'POST':
          form = Answer(request.POST)
  
          if form.is_valid():
          #Here I want to make the comparison
              pass
      return render(request,"quiz_app/quiz.html",context_dict)
  </code></pre>
  
  <p>HTML:</p>
  
  <pre><code>&lt;table&gt;
          {% for q in questions %}
              &lt;tr&gt;
                  &lt;td&gt;{{ q.question }}&lt;/td&gt;       
                  &lt;form method="POST"&gt;
                      &lt;td&gt;{{ form.answer }}&lt;/td&gt;
                      {% csrf_token %}
                  &lt;td&gt;
                      &lt;input type="submit" value="submit"&gt;
                  &lt;/td&gt;
                  &lt;/form&gt;
              &lt;/tr&gt;
          {% endfor %}
      &lt;/table&gt;
  </code></pre>