Home > Enterprise >  Store list variable with Avg function in a Django aggregate
Store list variable with Avg function in a Django aggregate

Time:03-21

How to store and pass multiple Avg function in an aggregate the code below gives error of type

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)  

CodePudding user response:

Use args

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)  
  • Related