-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
views.py
29 lines (26 loc) · 977 Bytes
/
views.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
from rest_framework import viewsets
from .models import ListModel
from . import serializers
from utils.page import MyPageNumberPagination
from rest_framework.filters import OrderingFilter
from django_filters.rest_framework import DjangoFilterBackend
from .filter import Filter
class APIViewSet(viewsets.ModelViewSet):
"""
list:
Response a data list(all)
"""
pagination_class = MyPageNumberPagination
filter_backends = [DjangoFilterBackend, OrderingFilter, ]
ordering_fields = ['id', "create_time", "update_time", ]
filter_class = Filter
def get_queryset(self):
if self.request.user:
return ListModel.objects.filter(is_delete=False)
else:
return ListModel.objects.none()
def get_serializer_class(self):
if self.action in ['list']:
return serializers.BinpropertyGetSerializer
else:
return self.http_method_not_allowed(request=self.request)