title: Updating model field in django not working properly at runtime
body: <p>I have a model Product and another model Damaged. In the Damaged model I add the number of damaged quantity of a certain product. Now, I need that damaged_quantity to be reduced from the stock field in the Product model when the foreign key matches. The code works when I have added a damaged_quantity in the Damaged model but when there is no damaged_quantity of a certain product it throws type error so I tried like this in template but it is not working.  </p>
  
  <blockquote>
    <p>models.py</p>
  </blockquote>
  
  <pre><code>class Product(models.Model):
      name = models.CharField(max_length=250)
      quantity = models.IntegerField()
  
      @property
      def current_quantity(self):
          return self.quantity - self.damaged_set.all().aggregate(sum=Sum('damaged_quantity')).get('sum', 0)
  
  class Damaged(models.Model):
      product = models.ForeignKey('Product', on_delete=models.CASCADE)
      damaged_quantity = models.IntegerField(default=0)
  </code></pre>
  
  <blockquote>
    <p>template</p>
  </blockquote>
  
  <pre><code>    &lt;td&gt;
          {% for damage in damaged %}
                  {% if damage.product_id == product.id %}
                  {{product.current_quantity}}
                  {% else %}
                  {{ product.quantity }} # else part not working properly.
                  {% endif %}
           {% endfor %}
      &lt;/td&gt;
  </code></pre>