1👍
✅
You can filter the investment_set
and thus only retain the Investment
s with status='received'
:
@property
def amount_invested(self):
return self.investment_set.filter(
status='received'
).aggregate(Sum('invested'))['invested__sum'] or 0
Source:stackexchange.com