Hello guys im practicing on django by now developping a simple expense tracker for a main project expample: Buying a flippable car for X amount and adding all the other expenses to get a single total.
my operation is mainly done in my model.py
models.py
from django.db import models
# Create your models here.
class Project(models.Model):
title = models.CharField(max_length=100)
amount = models.FloatField()
description = models.TextField(blank=True, null=True)
def __str__(self):
return self.title
class Expenses(models.Model):
project = models.ForeignKey(Project, related_name='expenses', on_delete=models.CASCADE)
title = models.CharField(max_length=100)
amount = models.FloatField()
def __str__(self):
return self.title
def get_total_project_amount(self):
return self.amount + self.project.amount
What i wanna do is adding the main project and all the expenses togheter, but im not using the proper way, when i render the resuld it renders like this:
main project: 50$ expenses added from a model form : 2(new) expense: 13(new) expense: 25(new)
the total is: 52 total: 63 total: 75
I wanna render the main project and all the expenses to get a single result, something like 50+2+13+25 total : 90$ total amount soent to fix the car.
Anyone that understand addition lojic help please and thank you
.