I've been attempting unsuccessfully to show the total_net_interest on my dashboard. I think there is a problem with my strategy. Does anyone have a solution to this issue?
Model
class Investment(models.Model):
PLAN_CHOICES = (
("Basic - Daily 2% for 182 Days", "Basic - Daily 2% for 182 Days"),
("Premium - Daily 4% for 365 Days", "Premium - Daily 4% for 365 Days"),
)
plan = models.CharField(max_length=100, choices=PLAN_CHOICES, null=True)
principal_amount = models.IntegerField(default=0, null=True)
investment_id = models.CharField(max_length=10, null=True, blank=True)
is_active = models.BooleanField(default=False)
created_at = models.DateTimeField(auto_now=True, null=True)
due_date = models.DateTimeField(null=True, blank=True)
def daily_interest(self):
if self.plan == "Basic - Daily 2% for 182 Days":
return self.principal_amount * 365 * 0.02/2/182
else:
return self.principal_amount * 365 * 0.04/365
def net_interest(self):
if self.plan == "Basic - Daily 2% for 182 Days":
return self.principal_amount * 365 * 0.02/2
else:
return self.principal_amount * 365 * 0.04
def total_net_interest(self):
return self.Investment.aggregate(total_net_interest=Sum('net_interest'))['total_net_interest']