title: How do I pass an instance to a view?
body: <p>I'm not able to understand the complaint that the system is returning.
  Here is the view for the system</p>
  <pre><code> def AddMarksView(request):
          class_name = request.session.get('class_name')
          subject = Subject.objects.filter(name='Maths')
          exam = Exam.objects.filter(name='Endterm')
          students =  Students.objects.filter(school=request.user.school,klass__name = class_name,stream__name='South')
          if request.method == 'POST':
              for student in students:
                  marks = int(request.POST['marks'])
                  marks_object = Marks.objects.create(student=student,marks=marks,subject=subject,exam=exam)
          else:
              return render(request,'feed_marks.html')
          return redirect('search_m')
  </code></pre>
  <p>The error returned is</p>
  <pre><code>Cannot assign &quot;&lt;QuerySet [&lt;Exam: Endterm&gt;]&gt;&quot;: &quot;Marks.exam&quot; must be a &quot;Exam&quot; instance.
  </code></pre>
  <p>The model for Marks odel is</p>
  <pre><code>class Marks(models.Model):
      exam = models.ForeignKey(Exam,on_delete=models.SET_NULL,null=True,blank=True)
      subject = models.ForeignKey(Subject,on_delete=models.SET_NULL,null=True,blank=True)
      student = models.ForeignKey(Students,on_delete=models.SET_NULL,null=True,blank=True)
      marks = models.IntegerField(validators=[MinValueValidator(0), MaxValueValidator(100),] ,null=True,blank=True)
  </code></pre>
  <p>How can I format the view so tha it returns no error?</p>