views.py 758 B

1234567891011121314151617181920212223
  1. from django.db.models import Sum
  2. from rest_framework import status
  3. from rest_framework.response import Response
  4. from rest_framework.views import APIView
  5. from rest_framework.viewsets import ModelViewSet
  6. from basic.models import Menu
  7. from basic.serializer import MenuSerializer
  8. from payment.models import Payment
  9. class MenuView(ModelViewSet):
  10. queryset = Menu.objects.all()
  11. serializer_class = MenuSerializer
  12. pagination_class = None
  13. filter_fields = {'code': ['exact'], 'parent': ['exact']}
  14. class StatisticsView(APIView):
  15. def get(self, request):
  16. data = list(
  17. Payment.objects.values('payment_type').annotate(price_sum=Sum('index_price')).order_by('-price_sum'))
  18. return Response(data, status=status.HTTP_200_OK)