The*_*eve 2 python django django-templates django-models django-views
我正在尝试制作一个表格,显示计划中每个金融机构的总到期金额.
计划是我用于人的术语.因此每个人都可以进行多项投资.我在创建一个能够正确执行此操作的表时遇到问题.
目前我有一份报告显示按到期日分类的每项投资,即2011,2012等.
在底部我想放置这个摘要表,但我的查询显示每个金融机构的重复,因为能够进行多次投资.
我目前的查询:
list = Investment.objects.all().filter(plan = plan).order_by('financial_institution').filter(maturity_date__gte= '%s-1-1' % current_year).distinct()
Run Code Online (Sandbox Code Playgroud)
这将输出:
但我想:
因此,您希望聚合计划的投资值:
from django.db.models import Sum
my_plan.investment_set.filter(
maturity_date__gte=whenever
).values('financial_institution').annotate(Sum('value'))
Run Code Online (Sandbox Code Playgroud)