|
|
|
@ -1,13 +1,18 @@ |
|
|
|
|
from django.http import JsonResponse |
|
|
|
|
from django.db.models import Q |
|
|
|
|
from rest_framework import viewsets, permissions, status |
|
|
|
|
from rest_framework import viewsets, permissions, status, filters |
|
|
|
|
from update.models import Cinema |
|
|
|
|
from update.serializers import CinemaSerializer |
|
|
|
|
from rest_framework.views import APIView |
|
|
|
|
from rest_framework.response import Response |
|
|
|
|
from rest_framework_extensions.cache.mixins import CacheResponseMixin |
|
|
|
|
from django.utils.decorators import method_decorator |
|
|
|
|
from django.views.decorators.cache import cache_page |
|
|
|
|
from django_filters.rest_framework import DjangoFilterBackend |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class CinemaViewSet(viewsets.ModelViewSet): |
|
|
|
|
# CacheResponseMixin 一定要放第一位 |
|
|
|
|
class CinemaViewSet(CacheResponseMixin, viewsets.ModelViewSet): |
|
|
|
|
# 接口文档的中文注释 |
|
|
|
|
""" |
|
|
|
|
create: 添加测试影院 |
|
|
|
@ -19,9 +24,13 @@ class CinemaViewSet(viewsets.ModelViewSet): |
|
|
|
|
queryset = Cinema.objects.all() |
|
|
|
|
serializer_class = CinemaSerializer |
|
|
|
|
permission_classes = (permissions.IsAuthenticated,) |
|
|
|
|
filter_backends = (filters.SearchFilter, DjangoFilterBackend) |
|
|
|
|
search_fields = ('ip', 'sys_ver') |
|
|
|
|
# filter_fields = ('ip', 'sys_ver') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class CinemaSearchAPIView(APIView): |
|
|
|
|
class CinemaSearchAPIView(APIView, CacheResponseMixin): |
|
|
|
|
@method_decorator(cache_page(60 * 5)) |
|
|
|
|
def get(self, request, *args, **kwargs): |
|
|
|
|
query_params = request.query_params.dict() |
|
|
|
|
print(query_params) |
|
|
|
|