Added some logic
This commit is contained in:
19
backend/apps/books/views.py
Normal file
19
backend/apps/books/views.py
Normal file
@@ -0,0 +1,19 @@
|
||||
from rest_framework import viewsets
|
||||
|
||||
from apps.books.models import Book
|
||||
from apps.books.serializers import BookSerializer
|
||||
from rest_framework import viewsets
|
||||
from rest_framework.permissions import IsAuthenticated
|
||||
from rest_framework_simplejwt.authentication import JWTAuthentication
|
||||
|
||||
class BooksViewSet(viewsets.ModelViewSet):
|
||||
queryset = Book.objects.prefetch_related("authors")
|
||||
serializer_class = BookSerializer
|
||||
|
||||
authentication_classes = [JWTAuthentication]
|
||||
permission_classes = [IsAuthenticated]
|
||||
|
||||
def get_queryset(self):
|
||||
return self.queryset.filter(
|
||||
shelf__user_id=self.request.user.pk
|
||||
)
|
||||
Reference in New Issue
Block a user