Skip to content

Commit 6a4ef26

Browse files
Daan van der Kallendaanvdk
authored andcommitted
Add max_values option to stats
1 parent 12e4845 commit 6a4ef26

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

binder/views.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@
4242
# annotations: a list of annotation names that have to be applied to the queryset for the expr to work (optional),
4343
Stat = namedtuple(
4444
'Stat',
45-
['expr', 'filters', 'group_by', 'annotations', 'min_value'],
46-
defaults=[{}, None, [], None],
45+
['expr', 'filters', 'group_by', 'annotations', 'min_value', 'max_values'],
46+
defaults=[{}, None, [], None, None],
4747
)
4848

4949

@@ -3041,6 +3041,11 @@ def _get_stat(self, request, queryset, stat, annotations, include_annotations):
30413041
else:
30423042
other = 0
30433043

3044+
elif stat.max_values is not None:
3045+
keys = sorted(value, key=lambda key: value[key], reverse=True)
3046+
for key in keys[stat.max_values:]:
3047+
other += value.pop(key)
3048+
30443049
return {
30453050
'value': value,
30463051
'other': other,

0 commit comments

Comments
 (0)