Add filter backend for storage model in API

This commit is contained in:
Mario Hüttel 2021-12-30 21:55:35 +01:00
parent a73fba0f1b
commit e6eb9346a8
3 changed files with 6 additions and 1 deletions

View File

@ -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,6 +43,8 @@ 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()

View File

@ -41,6 +41,7 @@ INSTALLED_APPS = [
'parts.apps.PartsConfig',
'api.apps.ApiConfig',
'rest_framework.authtoken',
'django_filters',
'qr_code',
'rest_framework',
'crispy_forms',

View File

@ -58,6 +58,7 @@ INSTALLED_APPS = [
'parts.apps.PartsConfig',
'api.apps.ApiConfig',
'rest_framework.authtoken',
'django_filters',
'qr_code',
'rest_framework',
'crispy_forms',