Question: I am trying to get the data from ManyToManyField model.I have two model question and quiz\_spes in manytomanyfield i am trying to access all question of particular quiz\_spec 
My model is following.My model is following

```
class quiz_spec(models.Model):
   title=models.TextField()
   course = models.ForeignKey(Course)
   start_date = models.DateField()
   end_date = models.DateField()
   duration = models.IntegerField()
   credit=models.IntegerField()

 def __str__(self):
    return self.title 

```

and question model is 

```
class question(models.Model):
    CHOICES = (
    ('option 1','a'),
    ('option 2','b'),
    ('option 3','c'),
    ('option 4','d'),
  )
   statement = models.TextField()
   a = models.TextField()
   b = models.TextField()
   c = models.TextField()
   d = models.TextField()
   addedBY=models.ForeignKey(faculty_profile,null=True)
   ans = models.CharField(max_length=1,choices=CHOICES)
   category=models.TextField()
   extra_info=models.TextField()
   quizes = models.ManyToManyField(quiz_spec,blank=True,null=True)
   dateAdded = models.DateTimeField(auto_now=True); 

```

my view is

```
def quiz_confirm(request):
       quiz=quiz_spec.objects.get(id=request.session['quiz_id'])
       print request.session['quiz_id']
       print quiz
       try:
          questions=question.objects.all().filter(quizes=quiz)
       except Exception as e:
        print e
      print questions
     return render(request, 'quiz_confirm.html')

```

it is giving [] output.but quiz is not null.

Answer: 
Have you tried querying the questions like:

```
questions = question.objects.filter(quizes__in=[quiz])

```

Or can you get the questions from the quiz side by querying:

```
questions = quiz.question_set.all()

```

that should return all the questions connected to quiz.
You should use 

`questions = question.objects.filter(quizes__contains=quiz)`