title: Django: Loop over 2 objects in same loop in template
body: <p>I have two models that are related, and I need to create a table that takes from both objects.</p>
  
  <p>In my models:</p>
  
  <pre><code>class Chamber(models.Model):
      chamber_name = models.CharField(max_length=100)
      chamber_type = models.CharField(max_length=50)
      customer = models.ForeignKey(Customer, on_delete=models.CASCADE)
  
  class ChamberProperties(models.Model):
      chamber = models.ForeignKey(Chamber, on_delete=models.CASCADE)
      property_name = models.CharField(max_length=20)
      property_value = models.CharField(max_length=100)
  </code></pre>
  
  <p>The structure is strange, but it's too late to just add properties and values to the chamber model. I'll have to live with the fact that they are two separate models.</p>
  
  <p>In my table I need the following structure:</p>
  
  <p>chamber_name(obj A) - property_value(obj B) - customer(obj A again)</p>
  
  <p>I tried zipped lists, but I don't seem to be able to unpack it:</p>
  
  <pre><code>class ChambersView(generic.DetailView):
      template_name = 'pages/chambers.html'
  
      def get(self, request):
          user = User.objects.get(username=request.user)
          customer = Customer.objects.get(user=user)    
          chambers_list = list(Chamber.objects.filter(customer=customer))
          chamber_properties = list(ChamberProperties.objects.filter(chamber__in=chambers_list).order_by('id'))
          objects_list = zip(chamber_properties, chambers_list)
          form = ChambersFilterForm(request=request)
          return render(request, self.template_name, {'filter_form':form, 'objects_list': objects_list})
  </code></pre>
  
  <p>If I unpack it in python it works:</p>
  
  <pre><code>for properties, chambers in objects_list:
              print("-----------------------------------------------------------")
              print("Property is: ", properties.property_value, "and the chamber is:", chambers.chamber_name)
              print("-----------------------------------------------------------")
  </code></pre>
  
  <p>But when I go to my HTML template:</p>
  
  <pre><code>&lt;div class="card-body p-1"&gt;
      &lt;table class="table table-hover"&gt;
          &lt;tr class="table-active"&gt;
              &lt;th&gt;Chamber&lt;/th&gt;
              &lt;th&gt;Property Value&lt;/th&gt;
              &lt;th&gt;Customer&lt;/th&gt;
          &lt;/tr&gt;
          {% for properties, chambers in objects_list %}
              &lt;tr&gt;
                  &lt;td&gt;&lt;a href="{% url 'chamber' chamber.id %}"&gt;{{chambers.chamber_name}}&lt;/a&gt;&lt;/td&gt;
                  &lt;td&gt;&lt;a href="{% url 'chamber' chamber.id %}"&gt;{{properties.property_value}}&lt;/a&gt;&lt;/td&gt;
                  &lt;td&gt;&lt;a href="{% url 'chamber' chamber.id %}"&gt;{{chambers.customer}}&lt;/a&gt;&lt;/td&gt;
              &lt;/tr&gt;
          {% endfor %}
      &lt;/table&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>The table comes up empty. There are no errors, no logs, the server works fine. If I just do {{ objects_list }} <strong>outside</strong> of the for-loop I get "zip object at " in the HTML. So I know <strong>something</strong> is there. I just don't seem to be unpacking it properly because if I do {{objects_list}} <strong>inside</strong> the for loop, again nothing shows up.</p>
  
  <p>Any ideas? I would greatly appreciate any help in this matter. As a junior, I've searched around and I've seen some people override "get_context_data" for similar cases, but I wouldn't know how to do that yet or if it would be usable for this case.</p>