martsberger / django-pivot

A module for pivoting Django Querysets
MIT License
210 stars 16 forks source link

Django Rest FrameWorks #14

Closed fjbardelli closed 1 year ago

fjbardelli commented 4 years ago

is it possible to serialize the result in DRF?

tombohub commented 3 years ago

I did it:

from rest_framework.response import Response
from rest_framework.decorators import api_view

@api_view()
def inventory_stock(request):
   stock = pivot(Transaction, 'product__name',
                  'location__name', 'quantity')
    return Response(stock)
martsberger commented 1 year ago

The result of a call to pivot is a list of dictionaries, as long as the values in the dictionaries are serializable you can write a serializer for it. The django-pivot library is not opinionated on what you do with the data.