MrOzOn 5 سال پیش
والد
کامیت
b2d0f3d4e2
3فایلهای تغییر یافته به همراه15 افزوده شده و 3 حذف شده
  1. 7 0
      apps/indicator/views.py
  2. 6 2
      healthdiarybackend/settings.py
  3. 2 1
      requirements.txt

+ 7 - 0
apps/indicator/views.py

@@ -1,4 +1,6 @@
+import django_filters
 from django.shortcuts import render
+from django_filters.rest_framework import DjangoFilterBackend
 from rest_framework import viewsets
 
 from apps.indicator.models import Indicator
@@ -23,3 +25,8 @@ class IndicatorViewSet(viewsets.ModelViewSet):
     #     return obj
 
     serializer_class = IndicatorSerializer
+    filter_backends = [DjangoFilterBackend]
+    filterset_fields = ['type']
+
+
+# https://www.django-rest-framework.org/api-guide/filtering/

+ 6 - 2
healthdiarybackend/settings.py

@@ -45,7 +45,8 @@ INSTALLED_APPS = [
     'rest_framework.authtoken',
     'apps.patient',
     'apps.indicatortype',
-    'apps.indicator'
+    'apps.indicator',
+    'django_filters',
 ]
 
 MIDDLEWARE = [
@@ -140,5 +141,8 @@ REST_FRAMEWORK = {
     ],
     'DEFAULT_PERMISSION_CLASSES': [
             'rest_framework.permissions.IsAuthenticated',
-    ]
+    ],
+    # 'DEFAULT_FILTER_BACKENDS': [
+    #     'django_filters.rest_framework.DjangoFilterBackend',
+    # ]
 }

+ 2 - 1
requirements.txt

@@ -1,3 +1,4 @@
 Django==3.0.8
 djangorestframework==3.11.0
-Pillow==7.2.0
+Pillow==7.2.0
+django-filter==2.3.0