{"id":21189309,"url":"https://github.com/uptick/django-rest-framework-aggregates","last_synced_at":"2025-07-10T02:31:45.459Z","repository":{"id":49699171,"uuid":"114184756","full_name":"uptick/django-rest-framework-aggregates","owner":"uptick","description":"Exposes aggregation features of the Django model queryset to the DRF API.","archived":false,"fork":false,"pushed_at":"2022-09-15T07:05:27.000Z","size":42,"stargazers_count":23,"open_issues_count":3,"forks_count":7,"subscribers_count":12,"default_branch":"master","last_synced_at":"2024-04-14T04:18:40.329Z","etag":null,"topics":["django","django-rest-framework"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/uptick.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-12-14T00:58:07.000Z","updated_at":"2024-04-14T04:18:40.329Z","dependencies_parsed_at":"2022-09-26T20:20:35.071Z","dependency_job_id":null,"html_url":"https://github.com/uptick/django-rest-framework-aggregates","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uptick%2Fdjango-rest-framework-aggregates","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uptick%2Fdjango-rest-framework-aggregates/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uptick%2Fdjango-rest-framework-aggregates/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uptick%2Fdjango-rest-framework-aggregates/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/uptick","download_url":"https://codeload.github.com/uptick/django-rest-framework-aggregates/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225265009,"owners_count":17446757,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["django","django-rest-framework"],"created_at":"2024-11-20T18:51:42.152Z","updated_at":"2024-11-20T18:51:42.889Z","avatar_url":"https://github.com/uptick.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# django-rest-framework-aggregates\n[![PyPI version](https://badge.fury.io/py/drf-aggregates.svg)](https://badge.fury.io/py/drf-aggregates) [![Build Status](https://travis-ci.org/uptick/django-rest-framework-aggregates.svg?branch=master)](https://travis-ci.org/uptick/django-rest-framework-aggregates)\n\nExposes aggregation features of the Django model queryset to the DRF API.\n\n## Requirements\n\n - Python 3.6+\n - Django 1.11+\n - Django Rest Framework 3.5.3+\n\n## Overview\n\nThis renderer overwrites default behaviour for calls made to api v2 .agg endpoints.\n\nSupports `GET` calls to list endpoints in the format:\n\n    endpoint.agg/?aggregate[Count]=(field to count)\n    endpoint.agg/?aggregate[Sum]=(field to sum)\n    endpoint.agg/?aggregate[custom_function]=arguments\n    endpoint.agg/?group_by[field to group by]\u0026aggregate[Count]=id\n    endpoint.agg/?group_by[field to group by]\u0026aggregate[Count]=id\u0026aggregate[Sum]=(field to sum)\n\nSupports date part extraction for aggregation:\n\n    endpoint.agg/?group_by[created__year]\u0026aggregate[Count]=id\n\nSupports choices to representation extract:\n\n    endpoint.agg/?group_by[choiceField]\u0026aggregate[Count]=id\n\nSupport aggregating over multiple fields, either of\n```\nendpoint.agg/?aggregate[Sum]=id\u0026aggregate[Sum]=number\nendpoint.agg/?aggregate[Sum]=id,number\n```\n## Custom Aggregations\n\nThe default aggregate functions supported are defined in `django.db.models.aggregates`.\n\nCustom aggregate functions have been defined in `drf_aggregates.aggregates`\n\nUser defined aggregation are passed to a custom queryset manager `calculate_aggregates` as kwargs if defined.\n\nCustom aggregate functions set on the queryset should return a dictionary of field names to aggregate functions, which will then be processed with the other aggregates.\n\n## Examples\n\nExample setup can be found in the [example/](/example/) folder.\n\nTo enable the renderer, update your Django settings file:\n\n  ```python\n    REST_FRAMEWORK = {\n        'DEFAULT_RENDERER_CLASSES': (\n            'drf_aggregates.renderers.AggregateRenderer',\n            ...\n        ),\n        ...\n    }\n  ```\n\nIn the [Cars ViewSet](/example/api/views.py) we are outputting the result to json:\n\n  ```python\n\n      def list(self, request, *args, **kwargs):\n          queryset = self.filter_queryset(self.get_queryset())\n          data = request.accepted_renderer.render({'queryset': queryset, 'request': request})\n          return Response(data, content_type=f'application/json')\n  ```\n\n\n## Tests\n\nIn order to run tests locally:\n\n1. Install development requirements:\n\n    `pip3 install -r requirements-dev.txt`\n\n2. Update your environment to point to test Django settings file:\n\n    `export DJANGO_SETTINGS_MODULE=example.settings.test`\n\n3. Run tests:\n\n    `py.test`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fuptick%2Fdjango-rest-framework-aggregates","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fuptick%2Fdjango-rest-framework-aggregates","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fuptick%2Fdjango-rest-framework-aggregates/lists"}