A Django REST Framework mixin that adds an aggregation endpoint (count, sum, average, minimum, maximum) with grouping, filtering and ordering to your ViewSets.
uv add django-rest-aggregationfrom django_rest_aggregation import AggregationMixin
from rest_framework.viewsets import GenericViewSet
class BookViewSet(AggregationMixin, GenericViewSet):
queryset = Book.objects.all()
serializer_class = BookSerializerGET /book/aggregation/?aggregation=average&aggregation_field=rating&group_by=author
Based on kit-oz/drf-aggregation.
The documentation is split into small linked notes in Readme/.
Using the package
- Installation: install, dependencies,
INSTALLED_APPS - Quickstart: add the mixin, register the route, example requests and responses
- Query parameters: all URL parameters at a glance
- Aggregations: aggregation types, aliases, allowed field types
- Grouping:
group_by, relation paths, multiple fields - Filtering: filtering before and after aggregation, value FilterSets
- Ordering:
ordering, allowed fields, pitfalls - Field access: which fields
group_by/aggregation_fieldmay use (aggregation_fields,aggregation_models), limits - Customization: value name, serializer, pagination, overridable hooks
- View attributes: reference of all class attributes
Working on the package
- Architecture: modules and request flow
- Development: setup, tests, lint, release
- Issues: open bugs, packaging problems and ideas
MIT, see LICENSE.