title: How to get an object's id and use it for child's query?
body: <pre><code>def customer(request, customer_id):
       &quot;&quot;&quot;Displays customer profile&quot;&quot;&quot;
       customer = Customer.objects.get(id=customer_id)
       entries = customer.entry_set.order_by('-date_added')
       subentry = SubEntry.objects.get()
       context = {'customer': customer, 'entries': entries, 'subentry': subentry}
       return render(request, 'crm/customer.html', context)
  </code></pre>
  <p>I have three classes, Customer, Entry and SubEntry. Customer is a ForeignKey to Entry and Entry is a ForeignKey to SubEntry. Each class has a textfield whose id I can access through the python shell. Currently, I have customer.html displaying a loop that iterates through the <code>entries</code> for a <code>customer</code>, but one <code>subentry</code> prints on all <code>entries</code> instead of printing the correct unique text. Is there are better way to show this information and print out the <code>subentry</code> for each entry?</p>
  <p>The snippet below is an example of how each class looks like:</p>
  <pre class="lang-py prettyprint-override"><code>class SubEntry(models.Model):
      entry = models.ForeignKey(Entry, on_delete=models.CASCADE)
      text = models.TextField(default='')
      date_added = models.DateTimeField(auto_now_add=True)
      owner = models.ForeignKey(User, on_delete=models.PROTECT)
  
      class Meta:
          verbose_name_plural = 'Subentries'
  
      def __str__(self):
          return self.subentry
  </code></pre>
  <p>This is how I attempted to solve the issue:</p>
  <pre class="lang-py prettyprint-override"><code>def customer(request, customer_id, entry_id):     
  &quot;&quot;&quot;Displays cx profile&quot;&quot;&quot;     
  customer = Customer.objects.get(id=customer_id)     
  entries = customer.entry_set.order_by('-date_added')     unique_entry_id = Entry.objects.get(id=entry_id)     
  subentry = SubEntry.objects.get(unique_entry_id)     
  context = {'customer': customer, 'entries': entries, 'subentry': subentry,}     
  return render(request, 'crm/customer.html', context)
  </code></pre>
  <p>This revised code threw out a TypeError: customer() missing 1 required positional argument: 'entry_id'.</p>