How should I iterate over this dictionary of objects in this Django Template?
<p>I have the below view.</p>

<pre><code>def select_classes(request):
 ...
            classesBySelectedGrade = courseBlock.objects.filter(grades__grade__contains=form['grade'].value()).order_by(
                'time')
            classOptionCount = classesBySelectedGrade.all().count()    

            classOptionDict = {}    

            for i in range(classOptionCount):
                classOptionDict["option " + str(i + 1)] = classesBySelectedGrade    

    return render(request, 'select-classes.html', {'classesOptions': classOptionDict})
</code></pre>

<p>The goal of the above view: </p>

<ol>
<li>Is to take a set of "courses" sorted by time. </li>
<li>Create a copy of the set of course nth many times as courses.count() </li>
<li>Add each copy to a dictionary</li>
<li>Pass this dictionary to my template.</li>
</ol>

<p>Here is the data that is being passed.</p>

<pre><code> {
     'classesOptions': {
         'option 1': &lt; QuerySet[ &lt; courseBlock: Course Block: Some Course Block 1 - Start: 07: 00: 00, Endtime: 08: 00: 00: &gt; , &lt; courseBlock: Course Block: Some Course Block 2 - Start: 07: 00: 00, Endtime: 08: 00: 00: &gt; ] &gt; ,
         'option 2': &lt; QuerySet[ &lt; courseBlock: Course Block: Some Course Block 1 - Start: 07: 00: 00, Endtime: 08: 00: 00: &gt; , &lt; courseBlock: Course Block: Some Course Block 2 - Start: 07: 00: 00, Endtime: 08: 00: 00: &gt; ] &gt;
     }
 }
</code></pre>

<p>My current goal in my template: </p>

<ol>
<li>To iterate over passed in dictionary to read the values out.</li>
</ol>

<p>Here is the current loop I am using.</p>

<pre><code>{% for classesOption in classesOptions %}

    &lt;p&gt;
        {{ classesOption }}

        {% for classes in classesOption %}

            {{ classes }}

        {% endfor %}

    &lt;/p&gt;

{% endfor %}
</code></pre>

<p>And this is my output.</p>

<pre><code>option 2 o p t i o n 2
option 1 o p t i o n 1
</code></pre>

<p>The above output is expected with the particular data I am testing.
That is I am expecting 2 copies in this test case.</p>

<p>For more context here are my models: </p>

<pre><code>class Course(models.Model):
    title = models.CharField(max_length=200)
    limit = models.IntegerField(default=10)
    description = models.TextField(max_length=800)
    location = models.CharField(max_length=200, default="")
    teachers = models.TextField(max_length=800, default="")

class startEndTime(models.Model):
    endTime = models.TimeField()
    startTime = models.TimeField()

class courseBlock(models.Model):
    course = models.ManyToManyField(Course, related_name='course_in_block')
    grades = models.ManyToManyField(Grade, related_name='name_in_block')
    title = models.CharField(max_length=100)
    time = models.ForeignKey(startEndTime, on_delete=models.CASCADE)
</code></pre>