def get_average_values(self, queryset): """ Get the averages """ average = Item() average.custom_alias_name = "Averages" # the label for the averages row for field in self.fields_to_total: setattr(average, field, queryset.aggregate(Avg(field)).items()[0][1]) return average
def get_total_values(self, queryset): """ Get the totals """ #basically the total parameter is an empty instance of the given model total = Item() total.custom_alias_name = "Totals" # the label for the totals row for field in self.fields_to_total: setattr(total, field, queryset.aggregate(Sum(field)).items()[0][1]) return total