Browse Source

引入过滤库<Pipfile>
新增分页和过滤配置信息<settings.py>
支持title的不模糊搜索

DYaiu 4 years ago
parent
commit
2dfb52625b
3 changed files with 8 additions and 0 deletions
  1. 1 0
      Pipfile
  2. 6 0
      my_project/settings.py
  3. 1 0
      workreport/views.py

+ 1 - 0
Pipfile

@@ -11,6 +11,7 @@ django-restframework = "*"
 djangorestframework-bulk = "*"
 mysql = "*"
 mysqlclient = "*"
+django-filter = "*"
 
 [requires]
 python_version = "3.7"

+ 6 - 0
my_project/settings.py

@@ -119,3 +119,9 @@ USE_TZ = True
 # https://docs.djangoproject.com/en/3.0/howto/static-files/
 
 STATIC_URL = '/static/'
+
+REST_FRAMEWORK = {
+    'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.LimitOffsetPagination',
+    'PAGE_SIZE': 3,
+    'DEFAULT_FILTER_BACKENDS': ['django_filters.rest_framework.DjangoFilterBackend'],
+}

+ 1 - 0
workreport/views.py

@@ -25,3 +25,4 @@ class DailyReportViews(APIView):
 class ReportViews(ModelViewSet):
     queryset = DailyReport.objects.all()
     serializer_class = DailyReportSerializer
+    filter_fields = {'title': ['exact']}