title: Django aggregate(sum error
body: <p>I'm trying to sum a complete field after filtering objects using pk.</p>
  
  <p><strong>Views.py</strong></p>
  
  <pre><code>def items(request, pk):
      current_user = request.user
      selected_itemz = get_object_or_404(ItemIn, pk=pk)
      all_cats = Category.objects.all()
      cat_count = all_cats.count()
      item_count = ItemIn.objects.values_list('item_name', flat=True).distinct().count()  # returns a list of tuples..
      #all_units = Item.objects.aggregate(Sum('item_quantity'))['item_quantity__sum']
      ItemOut_table = ItemOut.objects.all().filter(item_name=selected_itemz)
      ItemOut_quantity = ItemOut_table.aggregate(Sum('item_quantity'))['item_quantity__sum']
  
      context = {
          #'all_units': all_units,
          'item_count': item_count,
          'cat_count': cat_count,
          'current_user': current_user,
          'ItemOut_quantity': ItemOut_quantity,
          'selected_itemz':selected_itemz,
      }
  
      return render(request, 'townoftech_warehouse/item_details.html', context)
  </code></pre>
  
  <p>Then I used an extra filter that I created which is <code>subtract</code> in my HTML</p>
  
  <p><strong>HTML</strong></p>
  
  <pre><code>  &lt;br&gt;
    &lt;br&gt;
    &lt;p align="right"&gt;
    الكمية الموجودة:
         {{ selected_itemz.item_quantity|subtract:ItemOut_quantity }}
        &lt;/p&gt;
    &lt;br&gt;
    &lt;br&gt;
  </code></pre>
  
  <p>and here is the <code>tempaltetags</code> file</p>
  
  <pre><code>from django import template
  
  register = template.Library()
  
  
  @register.filter
  def subtract(value, arg):
      return value - arg
  </code></pre>
  
  <p>Now I get the error : </p>
  
  <pre><code>TypeError at /item/1/
  unsupported operand type(s) for -: 'int' and 'NoneType'
  </code></pre>