在 Django 聚合中存储具有 Avg 函数的列表变量
Store list variable with Avg function in a Django aggregate
如何在聚合中存储和传递多个 Avg 函数下面的代码给出类型错误
views.py
riasec_avg =[Avg('realistic'),Avg('investigative'),Avg('artistic'),Avg('social'),Avg('enterprising'),Avg('conventional')]
context['riasec_male'] = Riasec_result.objects.filter(user__profile__gender='M').aggregate(riasec_avg)
context['riasec_female'] = Riasec_result.objects.filter(user__profile__gender='F').aggregate(riasec_avg)
使用参数
riasec_avg =(Avg('realistic'),Avg('investigative'),Avg('artistic'),Avg('social'),Avg('enterprising'),Avg('conventional'))
context['riasec_male'] = Riasec_result.objects.filter(user__profile__gender='M').aggregate(*riasec_avg)
context['riasec_female'] = Riasec_result.objects.filter(user__profile__gender='F').aggregate(*riasec_avg)
如何在聚合中存储和传递多个 Avg 函数下面的代码给出类型错误
views.py
riasec_avg =[Avg('realistic'),Avg('investigative'),Avg('artistic'),Avg('social'),Avg('enterprising'),Avg('conventional')]
context['riasec_male'] = Riasec_result.objects.filter(user__profile__gender='M').aggregate(riasec_avg)
context['riasec_female'] = Riasec_result.objects.filter(user__profile__gender='F').aggregate(riasec_avg)
使用参数
riasec_avg =(Avg('realistic'),Avg('investigative'),Avg('artistic'),Avg('social'),Avg('enterprising'),Avg('conventional'))
context['riasec_male'] = Riasec_result.objects.filter(user__profile__gender='M').aggregate(*riasec_avg)
context['riasec_female'] = Riasec_result.objects.filter(user__profile__gender='F').aggregate(*riasec_avg)