diff --git a/dingxin_toolbox_drf/settings.py b/dingxin_toolbox_drf/settings.py index b8c2fa8..17dc685 100644 --- a/dingxin_toolbox_drf/settings.py +++ b/dingxin_toolbox_drf/settings.py @@ -114,8 +114,10 @@ LANGUAGE_CODE = 'zh-hans' TIME_ZONE = 'Asia/Shanghai' USE_I18N = True +# USE_I18N = False USE_TZ = True +# USE_TZ = False # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/4.2/howto/static-files/ @@ -176,3 +178,8 @@ REST_FRAMEWORK = { # 跨域配置 CORS_ALLOW_CREDENTIALS = True CORS_ORIGIN_ALLOW_ALL = True + +# 默认时间格式 +# DATE_FORMAT = '%Y-%m-%d' # 设置日期格式为年/月/日 +# TIME_FORMAT = '%H:%M:%S' # 设置时间格式为小时:分钟 +# DATETIME_FORMAT = "%Y-%m-%d %H:%M:%S" # 设置日期时间格式为年/月/日 小时:分钟 diff --git a/update/serializers.py b/update/serializers.py index c0c8dba..e730e85 100644 --- a/update/serializers.py +++ b/update/serializers.py @@ -3,6 +3,8 @@ from update.models import Cinema class CinemaSerializer(serializers.ModelSerializer): + update_time = serializers.DateTimeField(format='%Y-%m-%d %H:%M:%S') + class Meta: model = Cinema fields = ('id', 'name', 'ip', 'zz_num', 'inner_id', 'db_user', 'db_pwd', 'sys_ver', 'client_ver', 'update_time') diff --git a/update/urls.py b/update/urls.py index b3e3550..2ae2dc1 100644 --- a/update/urls.py +++ b/update/urls.py @@ -14,7 +14,7 @@ Including another URLconf 1. Import the include() function: from django.urls import include, path 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) """ -from django.urls import path, include +from django.urls import path, re_path, include from update import views from rest_framework.routers import DefaultRouter @@ -22,5 +22,11 @@ router = DefaultRouter() router.register('cinema', views.CinemaViewSet, 'cinema') urlpatterns = [ + path('cinema/search/', views.CinemaSearchAPIView.as_view()), path('', include(router.urls)), + + # re_path(r'^cinema/search/ip/(?P[0-9.]*?)/version/(?P[\S]*?)/$', views.CinemaSearchAPIView.as_view()) + ] + +# &version=(?P[\S]*?) \ No newline at end of file diff --git a/update/views.py b/update/views.py index 2b02526..6b79de8 100644 --- a/update/views.py +++ b/update/views.py @@ -1,6 +1,10 @@ -from rest_framework import viewsets, permissions +from django.http import JsonResponse +from django.db.models import Q +from rest_framework import viewsets, permissions, status from update.models import Cinema from update.serializers import CinemaSerializer +from rest_framework.views import APIView +from rest_framework.response import Response class CinemaViewSet(viewsets.ModelViewSet): @@ -15,3 +19,13 @@ class CinemaViewSet(viewsets.ModelViewSet): queryset = Cinema.objects.all() serializer_class = CinemaSerializer permission_classes = (permissions.IsAuthenticated,) + + +class CinemaSearchAPIView(APIView): + def get(self, request, *args, **kwargs): + query_params = request.query_params.dict() + print(query_params) + query_data = Cinema.objects.filter( + Q(ip__contains=query_params.get('ip')) & Q(sys_ver__icontains=query_params.get('version'))) + serializer = CinemaSerializer(instance=query_data, many=True) + return Response(serializer.data, status=status.HTTP_200_OK)