add a method to the ExchangeRate model to calculate the new currency

This commit is contained in:
Andreas Zweili 2018-01-28 20:26:41 +01:00
parent 3dbb614bbb
commit 13ad0fe98e
1 changed files with 4 additions and 0 deletions

View File

@ -23,5 +23,9 @@ class ExchangeRate(models.Model):
exchange_rate_to_chf = models.DecimalField(max_digits=12,
decimal_places=5)
def exchange(_currency_id, _base_currency):
rate = ExchangeRate.objects.filter(name=_currency_id).latest('date')
return round(rate.exchange_rate_to_chf * _base_currency,2)
def __str__(self):
return str(self.name)