Aggregate Function In Django ✅

 aggregate() - It is a terminal clause for a queryset that, when invoked, return dictionary name-value pair.

Required Module: django.db.models import Avg, Min, Max, Sum, Count


Open views.py file and write this code

e.g. def home(request):
            stud_data=Student.objects.all();
            average=stud_data.aggregate(average('marks'))
            total=stud_data.aggregate(Sum('marks'))
            minimum=stud_data.aggregate(Min('marks'))
            maximum=stud_data.aggregate(Max('marks'))
            totalCount=stud_data.aggregate(Count('marks'))

 context {
'students':stud_data,'average':average,'total':total,'minimum':minimum,'maximum':maximum,'totalCount':totalCount
}



Post a Comment

2 Comments

  1. Very nice,������

    ReplyDelete
  2. i dont want dictionary how to render only the number

    ReplyDelete

Comment Rules :

1. Do not post Adult/illegal Links.
2. Try to comment in only मराठी / English Language.
3. Do not post other website's links which are useless.
4. Your Comment should be based on the Topic for other queries.
5. Do not use Abusive Language.
6. Respect each other.
Thank You for following the rules. Please Comment....