开发者

Looping through annotate query

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'))
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜