forked from WasinTh/rest_tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathviews.py
More file actions
26 lines (17 loc) · 739 Bytes
/
Copy pathviews.py
File metadata and controls
26 lines (17 loc) · 739 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
from rest_framework import generics
from library.models import Author, Book
from library.sample_3.serializers import AuthorSerializer, BookSerializer
class AuthorList(generics.ListCreateAPIView):
queryset = Author.objects.all()
serializer_class = AuthorSerializer
class AuthorDetail(generics.RetrieveUpdateDestroyAPIView):
queryset = Author.objects.all()
lookup_field = 'id'
serializer_class = AuthorSerializer
class BookDetail(generics.RetrieveUpdateDestroyAPIView):
def get_queryset(self):
return Book.objects.filter(id=self.kwargs.get('pk', None))
serializer_class = BookSerializer
class BookList(generics.ListAPIView):
queryset = Book.objects.all()
serializer_class = BookSerializer