BuyAndKnow/bk_api/bills/views.py
Stanislaw-Golebiewski 527d60c70c backend setup
2020-01-05 21:41:14 +01:00

80 lines
2.4 KiB
Python

from django.shortcuts import render
from rest_framework import viewsets, permissions, pagination
from .models import Tag, Product, ProductOnBill, Receipt, Shop, ShopTag
from .serializers import TagSerializer, ProductSerializer, ProductOnBillSerializer, ReceiptSerializer, ShopSerializer, ShopTagSerializer
class TagViewSet(viewsets.ModelViewSet):
queryset = Tag.objects.all()
# permission_classes = [permissions.AllowAny]
serializer_class = TagSerializer
def get_queryset(self):
return self.request.user.tags.all()
def perform_create(self, serializer):
serializer.save(owner=self.request.user)
class ShopTagViewSet(viewsets.ModelViewSet):
queryset = ShopTag.objects.all()
# permission_classes = [permissions.AllowAny]
serializer_class = ShopTagSerializer
def get_queryset(self):
return self.request.user.shop_tags.all()
def perform_create(self, serializer):
serializer.save(owner=self.request.user)
class ShopViewSet(viewsets.ModelViewSet):
queryset = Shop.objects.all()
# permission_classes = [permissions.AllowAny]
serializer_class = ShopSerializer
def get_queryset(self):
return self.request.user.shops.all()
def perform_create(self, serializer):
serializer.save(owner=self.request.user)
class ProductViewSet(viewsets.ModelViewSet):
queryset = Product.objects.all()
# permission_classes = [permissions.AllowAny]
serializer_class = ProductSerializer
def get_queryset(self):
return self.request.user.products.all()
def perform_create(self, serializer):
serializer.save(owner=self.request.user)
class ProductOnBillViewSet(viewsets.ModelViewSet):
queryset = ProductOnBill.objects.all()
# permission_classes = [permissions.AllowAny]
serializer_class = ProductOnBillSerializer
def get_queryset(self):
return self.request.user.products_on_bills.all()
def perform_create(self, serializer):
serializer.save(owner=self.request.user)
class StandardResultsSetPagination(pagination.PageNumberPagination):
page_size = 10
page_size_query_param = 'page_size'
class ReceiptViewSet(viewsets.ModelViewSet):
queryset = Receipt.objects.all()
serializer_class = ReceiptSerializer
pagination_class = StandardResultsSetPagination
def get_queryset(self):
return self.request.user.receipts.all()
def perform_create(self, serializer):
serializer.save(owner=self.request.user)