title: Django queryset sum and average values
body: <p>I have trouble in finding a sum and avg value of the shares bought, my code is as follows
  models.py</p>
  
  <pre><code>class Stock(models.Model):
      name = models.CharField(verbose_name='Name of Stock', max_length=300)
      user = models.ForeignKey(settings.AUTH_USER_MODEL, default=1)
      slug = models.SlugField(unique=True)
      purchase_price = models.DecimalField(verbose_name='Purchase Day Price', blank=True, null=True, max_digits=30, decimal_places=2)
      pre_price = models.DecimalField(verbose_name='Last Day Price', blank=True, null=True, max_digits=30, decimal_places=2)
      current_price = models.DecimalField(verbose_name='Current Price', blank=True, null=True, max_digits=30, decimal_places=2)
  
  class BuyStock(models.Model):
      user = models.ForeignKey(settings.AUTH_USER_MODEL, default=1)
      stock = models.ForeignKey(Stock, verbose_name='Search')
      quantity = models.IntegerField(verbose_name='Quantity Required',default=0)
      timestamp = models.DateTimeField(auto_now=True, auto_now_add=False)
  </code></pre>
  
  <p>views.py</p>
  
  <pre><code>def stock_bought(request):
      queryset = BuyStock.objects.filter(user=request.user)
      context = {'queryset': queryset}
      return render(request, 'stock/stock_bought_list.html', context)
  </code></pre>
  
  <p>stock_bought_list.html</p>
  
  <pre><code>{% for item in queryset %}
          &lt;tr&gt;
              &lt;td&gt;
                  &lt;a href="{{ item.get_absolute_url }}"&gt;{{ item.stock.name }}&lt;/a&gt;
              &lt;/td&gt;
              &lt;td&gt;
                {{ item.purchase_price }}
              &lt;/td&gt;
              &lt;td&gt;
                {{ item.quantity }}
              &lt;/td&gt;
          &lt;/tr&gt;
     {% endfor %}
  </code></pre>
  
  <p>Now if the user purchase same stock many times the list also shows that much times separately, but I want it to be as a single item(based on name) and sum of quantity and average of price, hope somebody can help me, thank you.</p>