title: Django Inline Formset - possible to follow foreign key relationship backwards?
body: <p>I'm pretty new to django so I apologize if this has an obvious answer.</p>
  
  <p>Say you have the following three models:</p>
  
  <pre><code>models.py
  
  class Customer(models.Model):
      name = models.CharField()
      slug = models.SlugField()
  
  class Product(models.Model):
      plu = models.Charfield()
      description = models.Charfield()
  
  class Template(models.Model):
      customer = models.ForeignKey(Customer)
      product = models.ForeignKey(Product)
      price = models.DecimalField()
  </code></pre>
  
  <p>The inline formset would look something like:</p>
  
  <pre><code>TemplateFormSet = inlineformset_factory(Customer, Template, extra=0, 
                  fk_name='customer', fields=('price'))
  </code></pre>
  
  <p>Is it possible to follow the Template formset's Product foreign key backwards so you could display the plu and description fields within the same table?</p>
  
  <p>For example something like this:</p>
  
  <pre><code>&lt;table&gt;
    &lt;tbody&gt;
    {% for obj in customer.template_set.all %}
      &lt;tr&gt;
        &lt;td&gt;{{ obj.product.plu }}&lt;/td&gt;
        &lt;td&gt;{{ obj.product.description }}&lt;/td&gt;
        &lt;td&gt;{% render_field formset.form.price class="form-control form-control-sm" %}&lt;/td&gt;
      &lt;/tr&gt;
    {% endfor %}
    &lt;/tbody&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>The formset's fields appear with the html above but the data from the bound form instance doesn't appear and I can't save by editing the empty fields.</p>
  
  <p>I've also tried below but each formset is repeated for each object (for x formsets there are x*x rows):</p>
  
  <pre><code>&lt;tbody&gt;
  {% for obj in customer.template_set.all %}
    {% for form in formset %}
      &lt;tr&gt;
        &lt;td&gt;{{ obj.product.plu }}&lt;/td&gt;
        &lt;td&gt;{{ obj.product.description }}&lt;/td&gt;
        &lt;td&gt;{% render_field form.price class="form-control" %}&lt;/td&gt;
      &lt;/tr&gt;
    {% endfor %}
  {% endfor %}
  &lt;/tbody&gt;
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/vl7FZ.jpg" rel="nofollow noreferrer">Basically I'm trying to go from the top portion of the image to the bottom</a></p>