def _get_aggregation_filter(func):
    """
    This is a filter factory that creates the following filters:
        - avg_of
        - sum_of
        - min_of
        - max_of
        - count_of
    Each one is used over a queryset and return the aggregation of
    the given field, e.g.:

    .. code-block:: html+django

        {{ myqueriset|avg_of:'field' }}
    """

    def aggregation_filter(queryset, field):
        aggregations = queryset.aggregate(aggregated=func(field))
        return aggregations['aggregated']

    return aggregation_filter