Sfoglia il codice sorgente

新增一个路由获取指定列的所有数据

DYaiu 4 anni fa
parent
commit
7a4d31246e
3 ha cambiato i file con 22 aggiunte e 1 eliminazioni
  1. 3 1
      my_project/urls.py
  2. 8 0
      workreport/urls.py
  3. 11 0
      workreport/views.py

+ 3 - 1
my_project/urls.py

@@ -13,9 +13,11 @@ 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.conf.urls import url
 from django.contrib import admin
-from django.urls import path
+from django.urls import path, include
 
 urlpatterns = [
     path('admin/', admin.site.urls),
+    url(r'^report/', include('workreport.urls'))
 ]

+ 8 - 0
workreport/urls.py

@@ -0,0 +1,8 @@
+from django.conf.urls import url
+from workreport.views import DailyReportViews
+
+urlpatterns = []
+
+urlpatterns += [
+    url(r'^dailyreport/', DailyReportViews.as_view())
+]

+ 11 - 0
workreport/views.py

@@ -1,3 +1,14 @@
 from django.shortcuts import render
 
 # Create your views here.
+from rest_framework import status
+from rest_framework.response import Response
+from rest_framework.views import APIView
+
+from workreport.models import DailyReport
+
+
+class DailyReportViews(APIView):
+    def get(self, request):
+        data = DailyReport.objects.values('title', 'content', 'create_at', 'create_by', 'id')
+        return Response(data=data, status=status.HTTP_200_OK)