title: Django query include join
body: <p>I tried to calculate the count of the increased and decreased competitor product price which are related to products. I couldn't handle it. Can I do this by overriding <code>get_context_data</code> method? I couldn't write a query to get the data from comp_product model. How can I handle this?</p>
  <p>Models:</p>
  <pre><code>class Product(models.Model):
      user       = models.ForeignKey(User, on_delete=models.CASCADE,related_name='products')
      category   = models.CharField(max_length=120)
      brand      = models.CharField(max_length=120)
      product    = models.CharField(max_length=120)
      price      = models.DecimalField(decimal_places=2,max_digits=100)
  
  class Comp_Product(models.Model):
      product     = models.ForeignKey(Product,on_delete=models.CASCADE, related_name=&quot;comp_products&quot;)
      competitor  = models.URLField()
      price       = models.DecimalField(decimal_places=2,max_digits=100)
      change      = models.FloatField()
      stock       = models.BooleanField()
      last_update = models.DateField(auto_now_add=True)
  </code></pre>
  <p>View:</p>
  <pre><code>class DashboardList(ListView):
  
      template_name='dashboard_by_user.html'
  
      def get_queryset(self):
          p = Product.objects.filter(user=self.request.user)
          return p
  
      def get_context_data(self, **kwargs):
          context = super().get_context_data(**kwargs)
          Products = context['object_list']
          context['distinct_category_count'] = Products.values('category').distinct().count()
          context['distinct_brand_count']    = Products.values('brand').distinct().count()
          context['product_count']           = Products.values('product').count()
          context['num_comp_products_with_lower_price'] = p.comp_products.filter(price__lt=p.price).count()
          context['num_comp_products_with_higher_price'] = p.comp_products.filter(price__gt=p.price).count()
  
          return context
  </code></pre>