All Projects → uptick → django-rest-framework-aggregates

uptick / django-rest-framework-aggregates

Licence: other
Exposes aggregation features of the Django model queryset to the DRF API.

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to django-rest-framework-aggregates

agent
Job tracker & performance platform
Stars: ✭ 26 (+13.04%)
Mutual labels:  django-rest-framework
Face-Recognition-System
Intelligent Facial Recognition with Django Restful IoT on Raspberry Pi
Stars: ✭ 46 (+100%)
Mutual labels:  django-rest-framework
lego
LEGO Backend
Stars: ✭ 48 (+108.7%)
Mutual labels:  django-rest-framework
Shappar
気軽に投票を【取れる】【見れる】【できる】アプリです。
Stars: ✭ 22 (-4.35%)
Mutual labels:  django-rest-framework
drf-SimpleJWT-React
Template Django + DRF + SimpleJWT + React project
Stars: ✭ 80 (+247.83%)
Mutual labels:  django-rest-framework
mathesar
Web application providing an intuitive user experience to databases.
Stars: ✭ 95 (+313.04%)
Mutual labels:  django-rest-framework
oms cms
A Django content management system focused on flexibility and user experience
Stars: ✭ 18 (-21.74%)
Mutual labels:  django-rest-framework
RabbitMQ-with-Django
Example for using Microservices with RabbitMQ in a Django Web-Application
Stars: ✭ 26 (+13.04%)
Mutual labels:  django-rest-framework
django-rest-live
Subscribe to updates from Django REST Framework over Websockets.
Stars: ✭ 48 (+108.7%)
Mutual labels:  django-rest-framework
django-rest-framework-yaml
YAML support for Django REST Framework
Stars: ✭ 27 (+17.39%)
Mutual labels:  django-rest-framework
mobileAudit
Django application that performs SAST and Malware Analysis for Android APKs
Stars: ✭ 140 (+508.7%)
Mutual labels:  django-rest-framework
PyQuotes
PyQuotes is a Django-based web application and REST API. That will allow you to launch an online quotes service.
Stars: ✭ 23 (+0%)
Mutual labels:  django-rest-framework
GSoC-Data-Analyser
Simple search for organisations participating/participated in the GSoC
Stars: ✭ 29 (+26.09%)
Mutual labels:  django-rest-framework
django-logic
Django Logic - easy way to implement state-based business logic with pure functions
Stars: ✭ 44 (+91.3%)
Mutual labels:  django-rest-framework
kamu
You favorite book library
Stars: ✭ 65 (+182.61%)
Mutual labels:  django-rest-framework
tscharts
Django REST framework-based Digital Patient Registration and EMR backend
Stars: ✭ 14 (-39.13%)
Mutual labels:  django-rest-framework
django-restframework-userprofile
Public Profile is a Django REST Framework based API that demos how to extends a default Django Auth User model with a Profile. In addition, the code also includes a demo client that show how to consume the API from a Client Web Application.
Stars: ✭ 24 (+4.35%)
Mutual labels:  django-rest-framework
django-tutorial
Django 4 tutorial projects
Stars: ✭ 11 (-52.17%)
Mutual labels:  django-rest-framework
instagram-api-clone
Instagram RESTful API clone made with Django REST framework
Stars: ✭ 56 (+143.48%)
Mutual labels:  django-rest-framework
elearning
e-learning django app (django, python)
Stars: ✭ 107 (+365.22%)
Mutual labels:  django-rest-framework

django-rest-framework-aggregates

PyPI version Build Status

Exposes aggregation features of the Django model queryset to the DRF API.

Requirements

  • Python 3.6+
  • Django 1.11+
  • Django Rest Framework 3.5.3+

Overview

This renderer overwrites default behaviour for calls made to api v2 .agg endpoints.

Supports GET calls to list endpoints in the format:

endpoint.agg/?aggregate[Count]=(field to count)
endpoint.agg/?aggregate[Sum]=(field to sum)
endpoint.agg/?aggregate[custom_function]=arguments
endpoint.agg/?group_by[field to group by]&aggregate[Count]=id
endpoint.agg/?group_by[field to group by]&aggregate[Count]=id&aggregate[Sum]=(field to sum)

Supports date part extraction for aggregation:

endpoint.agg/?group_by[created__year]&aggregate[Count]=id

Supports choices to representation extract:

endpoint.agg/?group_by[choiceField]&aggregate[Count]=id

Support aggregating over multiple fields, either of

endpoint.agg/?aggregate[Sum]=id&aggregate[Sum]=number
endpoint.agg/?aggregate[Sum]=id,number

Custom Aggregations

The default aggregate functions supported are defined in django.db.models.aggregates.

Custom aggregate functions have been defined in drf_aggregates.aggregates

User defined aggregation are passed to a custom queryset manager calculate_aggregates as kwargs if defined.

Custom 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.

Examples

Example setup can be found in the example/ folder.

To enable the renderer, update your Django settings file:

  REST_FRAMEWORK = {
      'DEFAULT_RENDERER_CLASSES': (
          'drf_aggregates.renderers.AggregateRenderer',
          ...
      ),
      ...
  }

In the Cars ViewSet we are outputting the result to json:

    def list(self, request, *args, **kwargs):
        queryset = self.filter_queryset(self.get_queryset())
        data = request.accepted_renderer.render({'queryset': queryset, 'request': request})
        return Response(data, content_type=f'application/json')

Tests

In order to run tests locally:

  1. Install development requirements:

    pip3 install -r requirements-dev.txt

  2. Update your environment to point to test Django settings file:

    export DJANGO_SETTINGS_MODULE=example.settings.test

  3. Run tests:

    py.test

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].