我想在日期范围查询搜索期间添加所有金额字段。我有一个收入模型,其中包括日期和金额字段。每当用户在两个日期之间进行选择时,我希望将查询结果的金额字段添加为合计。 以下是我尝试过的:
def SearchIncomeRange(request):
listIncome = Income.objects.all()
searchForm = IncomeSearchForm(request.POST or None)
if request.method == 'POST':
listIncome = Income.objects.filter(
description__icontains=searchForm['description'].value(),
date__range=[
searchForm['start_date'].value(),
searchForm['end_date'].value()
]
)
else:
searchForm = IncomeSearchForm()
paginator = Paginator(listIncome, 5)
page = request.GET.get('page')
paged_income = paginator.get_page(page)
context = {
'searchForm':searchForm,
}
return render(request, 'cashier/search_income_range.html', context)
我能够得到正确的搜索结果,但是得到总数我不知道如何在上面的查询中使用总和,并在分页中传递总数。所以应该有人来帮我。谢谢
你的查询集在哪里
编辑:
如果应用了任何筛选器,则应在分页中使用筛选的queryset传递queryset
我更改了您编写的代码,但您可以用一种很好的方式编写此代码。
相关问题 更多 >
编程相关推荐