diff --git a/binder/views.py b/binder/views.py index 54b6eff6..70421428 100644 --- a/binder/views.py +++ b/binder/views.py @@ -2982,20 +2982,27 @@ def _get_stat(self, request, queryset, stat, annotations, include_annotations): group_by = stat['group_by'] except KeyError: # No group by so just return a simple stat - return queryset.aggregate(result=stat['expr'])['result'] + return { + 'value': queryset.aggregate(result=stat['expr'])['result'], + 'filters': stat.get('filters', {}), + } group_by = group_by.replace('.', '__') - # The jsonloads/jsondumps is to make sure we can handle different - # types as keys, an example is dates. return { - jsonloads(jsondumps(key)): value - for key, value in ( - queryset - .order_by() - .values(group_by) - .annotate(_binder_stat=stat['expr']) - .values_list(group_by, '_binder_stat') - ) + 'value': { + # The jsonloads/jsondumps is to make sure we can handle different + # types as keys, an example is dates. + jsonloads(jsondumps(key)): value + for key, value in ( + queryset + .order_by() + .values(group_by) + .annotate(_binder_stat=stat['expr']) + .values_list(group_by, '_binder_stat') + ) + }, + 'group_by': group_by, + 'filters': stat.get('filters', {}), }