title: how to write a use defined function inside django models.py?
body: <p>I had written a function inside models.py which will calculate percentage. But it not showing the calculated values.</p>
  
  <p>I have written a function called 'cal_amount' in models.py performed the calculation. return the value to the model field. But it showing None when i called.</p>
  
  <pre><code>class Course(models.Model):
          price = models.FloatField("Price", blank=True, null=True)
          voucher_id = models.CharField(max_length=255,blank=True, null=True)
          voucher_amount = models.IntegerField(blank=True, null=True)
          discounted_amount = models.IntegerField(blank=True, null=True)
          def __str__(self):  
              return self.course_name
  
          def cal_amount(self):
               self.discounted_amount = (self.voucher_amount/100)*self.price
               return self.discounted_amount
  </code></pre>
  
  <p>What i want is calculated amount to be stored in discounted_amount. so i can use {{ obj.discounted_amount }} in html to view it along with actual price. Please suggest me a way.</p>