Sometimes we want to calculate something, like the sum of our products, or the average prices of something. That is when we use the aggregate method. To use the aggregate method, you first have to import an aggregate class
from django.db.models.aggregates import Count, Max, Min, Avg, Sumthen we can use it as follows
def say_hello(request): result = Product.objects.aggregate(count = Count('id')) #returns the no. of all products, since every product has an id. But if you use it in a different field with null values, it will return the number of fields that have a not null value. the proper way to do it is to use the id or primary key result1 = Product.objects.aggregate(min_price = Min('unit_price')) # returns the minimum price pass