Or, you can combine annotations and expressions to do something like this:
qs = LoanInformation.objects.annotate(outstanding=F("amount_to_pay") -
Func(F("payments__amount"), function="SUM))
loan = qs.get(id=loan_id)
loan.outstanding
On Friday, July 7, 2023 at 4:03:09 PM UTC+1 Thomas Couch wrote:
Hi Abdou, have a look at aggregation
(https://docs.djangoproject.com/en/4.2/topics/db/aggregation/)
In this case I think you'll want something like:
```
from django.db.models import Sum
# Where loan = the LoanInformation instance you're interested in
outstanding_balance = loan.amount_to_pay -
2 matches
Mail list logo