From e6eb9346a869f78e3025414f6554fe232bf5ae1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20H=C3=BCttel?= Date: Thu, 30 Dec 2021 21:55:35 +0100 Subject: [PATCH] Add filter backend for storage model in API --- shimatta_kenkyusho/api/views.py | 5 ++++- shimatta_kenkyusho/shimatta_kenkyusho/settings.py | 1 + shimatta_kenkyusho/shimatta_kenkyusho/settings_production.py | 1 + 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/shimatta_kenkyusho/api/views.py b/shimatta_kenkyusho/api/views.py index 078ca6c..78722a0 100644 --- a/shimatta_kenkyusho/api/views.py +++ b/shimatta_kenkyusho/api/views.py @@ -18,6 +18,7 @@ from rest_framework.authtoken.models import Token from rest_framework.throttling import AnonRateThrottle from rest_framework.decorators import action from rest_framework import filters +import django_filters.rest_framework # Create your views here. class UserViewSet(viewsets.ReadOnlyModelViewSet): @@ -42,7 +43,9 @@ class PartsStorageViewSet(viewsets.ModelViewSet): queryset = parts_models.Storage.objects.all() serializer_class = StorageSerializer permission_classes = [permissions.DjangoModelPermissions] - + filter_backends = [django_filters.rest_framework.DjangoFilterBackend] + filterset_fields = ['id', 'name', 'parent_storage'] + class PartsComponentViewSet(viewsets.ModelViewSet): queryset = parts_models.Component.objects.all() serializer_class = ComponentSerializer diff --git a/shimatta_kenkyusho/shimatta_kenkyusho/settings.py b/shimatta_kenkyusho/shimatta_kenkyusho/settings.py index a585807..ecb4816 100644 --- a/shimatta_kenkyusho/shimatta_kenkyusho/settings.py +++ b/shimatta_kenkyusho/shimatta_kenkyusho/settings.py @@ -41,6 +41,7 @@ INSTALLED_APPS = [ 'parts.apps.PartsConfig', 'api.apps.ApiConfig', 'rest_framework.authtoken', + 'django_filters', 'qr_code', 'rest_framework', 'crispy_forms', diff --git a/shimatta_kenkyusho/shimatta_kenkyusho/settings_production.py b/shimatta_kenkyusho/shimatta_kenkyusho/settings_production.py index 177ee0a..de1391f 100644 --- a/shimatta_kenkyusho/shimatta_kenkyusho/settings_production.py +++ b/shimatta_kenkyusho/shimatta_kenkyusho/settings_production.py @@ -58,6 +58,7 @@ INSTALLED_APPS = [ 'parts.apps.PartsConfig', 'api.apps.ApiConfig', 'rest_framework.authtoken', + 'django_filters', 'qr_code', 'rest_framework', 'crispy_forms',