Django-filter And Aggregate Functions
This is an app specific question: django-filter, here is a brief explanation for those who have not used it. f = ProductFilter(request.GET, queryset=Product.objects.all()) This l
Solution 1:
You mean something like this:
from django.db.models import Avg
classProductFilter(django_filters.FilterSet):
...
@propertydefavg(self):
qs = super(ProductFilter, self).qs
return qs.aggregate(Avg('price'))['id__avg']
So you're adding your own filter property and use it like this in your template:
{{ filter.avg }}
Post a Comment for "Django-filter And Aggregate Functions"