-
Notifications
You must be signed in to change notification settings - Fork 1
/
custom_view.py
48 lines (33 loc) · 1.4 KB
/
custom_view.py
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
from django.utils import timezone
from rest_framework.generics import ListAPIView, RetrieveAPIView, CreateAPIView, UpdateAPIView, DestroyAPIView
from rest_framework.permissions import IsAuthenticated
from rest_framework.viewsets import ModelViewSet
from common.custom_pagination import CustomPageNumberPagination
class CustomModelViewSet(ModelViewSet):
permission_classes = [IsAuthenticated]
pagination_class = CustomPageNumberPagination
def perform_create(self, serializer):
serializer.save(
created_at=timezone.now()
)
def perform_update(self, serializer):
serializer.save(
updated_at=timezone.now()
)
class CustomListAPIView(ListAPIView):
http_method_names = ['get', 'head', 'options']
permission_classes = [IsAuthenticated]
pagination_class = CustomPageNumberPagination
class CustomRetrieveAPIView(RetrieveAPIView):
http_method_names = ['get', 'head', 'options']
permission_classes = [IsAuthenticated]
class CustomCreateAPIView(CreateAPIView):
http_method_names = ['post']
permission_classes = [IsAuthenticated]
pagination_class = CustomPageNumberPagination
class CustomUpdateAPIView(UpdateAPIView):
http_method_names = ['put', 'patch']
permission_classes = [IsAuthenticated]
class CustomDestroyAPIView(DestroyAPIView):
http_method_names = ['delete']
permission_classes = [IsAuthenticated]