Initially I asked this question, and I wanted to give credit to Daniel. Here is the new issue I have however.
I have this which works great, but I'm having a minor issue.
total_list = plan.investment_set.filter(maturity_date__gte= '%s-1-1' % current_year).values('financial_institution').annota开发者_运维技巧te(Sum('maturity_amount'))
I'm having trouble displaying the financial institution name. When I loop through total list and put loop_variable.financial_institution it shows me the ID but not the name.
Any ideas on how to fix this?
Assuming that the "financial_institution" model has a name
field, I think you could just add it to the list of values you're asking for:
total_list = plan.investment_set.filter(
maturity_date__gte= '%s-1-1' % current_year
).values(
'financial_institution',
'financial_institution__name'
).annotate(Sum('maturity_amount'))
精彩评论