title: Iterate over several querysets in django template with nested loop
body: <p>I am making a hotell-page, and have made models for bookings and rooms. 
  I want to display the bookings related to a room in a table, and have the related bookings laying under the spesific room.<a href="https://i.stack.imgur.com/tAaOo.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/tAaOo.png" alt="the table for rooms and bookings"></a></p>
  
  <p>I show the code from the views.py file here:</p>
  
  <pre><code>def vaskehjelp(response):
  available_rooms = Room.objects.filter(available=True)
  room_nums = []
  context = {}
  for room in available_rooms:
      related_bookings = Booking.objects.filter(room=room)
      if related_bookings:
          room_nums.append(room.room_no)
          context[room.room_no] = related_bookings
  
  context["room_nums"] = room_nums
  context["available_rooms"] = available_rooms
  print(context)
  return render(response, "../templates/se_vaskbare_rom.html", context)
  </code></pre>
  
  <p>and the code from my template file here:</p>
  
  <pre><code>&lt;table class="table table-striped table-dark"&gt;
              &lt;tr class="thead-dark"&gt;
                  &lt;th scope="col"&gt;Room No.&lt;/th&gt;
                  &lt;th scope="col"&gt;Capacity&lt;/th&gt;
                  &lt;th scope="col"&gt;Room Type&lt;/th&gt;
              &lt;/tr&gt;
              {% for item in available_rooms %}
                  &lt;tr scope="row"&gt;
                      &lt;td&gt;{{ item.room_no }}&lt;/td&gt;
                      &lt;td&gt;{{ item.capacity }}&lt;/td&gt;
                      &lt;td&gt;{{ item.room_type }}&lt;/td&gt;
                  &lt;/tr&gt;
                  {% if item.room_no in room_nums %}
                      {% for booking in item.room_no %}
                          &lt;h1&gt;&lt;/h1&gt;
                          &lt;tr scope="row"&gt;
                              &lt;td&gt;{{ booking.cin_date }}&lt;/td&gt;
                              &lt;td&gt;ku&lt;/td&gt;
                              &lt;td&gt;{{ booking.cout_date }}&lt;/td&gt;
                          &lt;/tr&gt;
                      {% endfor %}
                  {% endif %}
              {% endfor %}
          &lt;/table&gt;
  </code></pre>
  
  <p>The problem is that the booking-element in the template code doesent seem to work. I dont manage to access the lists of bookings related to the current selected room. As you see i have an outer for loop to iterate over the rooms, and then the inner for loop iterate over the related bookings (only in case that room is in the "room_nums" list. The problem is (i think) that the <strong>for booking in item.room_no</strong> doesnt work, i dont get any info from the <strong>booking</strong> variable at least...</p>
  
  <p>In the table i should have had the check in and check out dates in the left and right column, but i dont get this information from the <strong>booking</strong> variable...</p>
  
  <p>ps: the idea is that item.room_no is referrering to a list in the context dictionary. I have tried other things, but this is the closest i have come. </p>
  
  <p>Here are the <strong>models</strong>:</p>
  
  <pre><code>class Room(models.Model):
  room_choices = [('S', 'Single Occupancy'), ('D', 'Double Occupancy'), ('F', 'Firemannsrom')]
  room_no = models.CharField(max_length=5)  # primary key
  available = models.BooleanField(default=False)
  capacity = models.IntegerField(default=None)
  room_type = models.CharField(choices=room_choices, max_length=1, default=None)
  price = models.IntegerField( blank=True, null=True)
  
  def __str__(self):
      return "Romnr: " + str(self.room_no) + " -- type:" + str(self.room_type)
  </code></pre>
  
  <p>and</p>
  
  <pre><code>class Booking(models.Model):
  #defaultRom = Room.objects.get(room_no='100')
  #defaultRomID = defaultRom.id
  room_choices = [('S', 'Single Occupancy'), ('D', 'Double Occupancy'), ('F', 'Firemannsrom')]
  bookingid = models.AutoField(db_column='BookingID', primary_key=True)  # Field name made lowercase.
  guest = models.ForeignKey('auth.User', on_delete=models.CASCADE)  # eller settings.AUTH_USER_MODEL
  cin_date = models.DateField(db_column='CIN_Date', blank=True, null=True,
                                  verbose_name='Check-In Date')  # Field name made lowercase.
  cout_date = models.DateField(db_column='COUT_Date', blank=True, null=True,
                                   verbose_name='Check-Out Date')  # Field name made lowercase.
  room_type = models.CharField(choices=room_choices, max_length=1, default=None)
  room = models.ForeignKey('Room', on_delete=models.CASCADE, db_column='Room', default=None)
  
  class Meta:
      managed = True
      db_table = 'Booking'
  
  def __str__(self):
      return "Bruker: " + self.guest.__str__() + " -- id:" + str(self.bookingid) + " -- Inndato: " +  self.cin_date.__str__() + " -- Utdato: " + self.cout_date.__str__() + " -- " + self.room.__str__()
  </code></pre>
  
  <p>Here is the the result of <strong>print(context)</strong>:</p>
  
  <pre><code>{'100': &lt;QuerySet [&lt;Booking: Bruker: email -- id:27 -- Inndato: 2020-03-27 -- Utdato: 2020-03-29 -- Romnr: 100 -- type:S&gt;]&gt;, '103': &lt;QuerySet [&lt;Booking: Bruker: olaNordmann -- id:26 -- Inndato: 2020-03-07 -- Utdato: 2020-03-15 -- Romnr: 103 -- type:D&gt;]&gt;, 'room_nums': ['100', '103'], 'available_rooms': &lt;QuerySet [&lt;Room: Romnr: 100 -- type:S&gt;, &lt;Room: Romnr: 103 -- type:D&gt;, &lt;Room: Romnr: 106 -- type:F&gt;, &lt;Room: Romnr: 101 -- type:S&gt;]&gt;}
  </code></pre>
  
  <p>Thanks in advance!  </p>