|
|
@@ -1,27 +1,19 @@ |
|
|
|
from rest_framework.response import Response |
|
|
|
from rest_framework.views import APIView |
|
|
|
from rest_framework import viewsets |
|
|
|
from rest_framework.authentication import TokenAuthentication, SessionAuthentication |
|
|
|
from rest_framework.permissions import IsAuthenticated |
|
|
|
from .models import Item, Invoice |
|
|
|
from .serializers import ItemSerializer, InvoiceSerializer |
|
|
|
|
|
|
|
|
|
|
|
class ItemList(APIView): |
|
|
|
class ItemViewSet(viewsets.ModelViewSet): |
|
|
|
queryset = Item.objects.all() |
|
|
|
serializer_class = ItemSerializer |
|
|
|
authentication_classes = [TokenAuthentication, SessionAuthentication] |
|
|
|
permission_classes = [IsAuthenticated] |
|
|
|
|
|
|
|
def get(self, request, invoice_key): |
|
|
|
items = Item.objects.filter(invoice=invoice_key) |
|
|
|
serializer = ItemSerializer(items, many=True) |
|
|
|
return Response(serializer.data) |
|
|
|
|
|
|
|
|
|
|
|
class InvoiceList(APIView): |
|
|
|
class InvoiceViewSet(viewsets.ModelViewSet): |
|
|
|
queryset = Invoice.objects.all() |
|
|
|
serializer_class = InvoiceSerializer |
|
|
|
authentication_classes = [TokenAuthentication, SessionAuthentication] |
|
|
|
permission_classes = [IsAuthenticated] |
|
|
|
|
|
|
|
def get(self, request): |
|
|
|
invoices = Invoice.objects.all() |
|
|
|
invoice_serializer = InvoiceSerializer(invoices, many=True) |
|
|
|
|
|
|
|
return Response(invoice_serializer.data) |