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.throttling import AnonRateThrottle
from rest_framework.decorators import action from rest_framework.decorators import action
from rest_framework import filters from rest_framework import filters
import django_filters.rest_framework
# Create your views here. # Create your views here.
class UserViewSet(viewsets.ReadOnlyModelViewSet): class UserViewSet(viewsets.ReadOnlyModelViewSet):
@ -42,7 +43,9 @@ class PartsStorageViewSet(viewsets.ModelViewSet):
queryset = parts_models.Storage.objects.all() queryset = parts_models.Storage.objects.all()
serializer_class = StorageSerializer serializer_class = StorageSerializer
permission_classes = [permissions.DjangoModelPermissions] permission_classes = [permissions.DjangoModelPermissions]
filter_backends = [django_filters.rest_framework.DjangoFilterBackend]
filterset_fields = ['id', 'name', 'parent_storage']
class PartsComponentViewSet(viewsets.ModelViewSet): class PartsComponentViewSet(viewsets.ModelViewSet):
queryset = parts_models.Component.objects.all() queryset = parts_models.Component.objects.all()
serializer_class = ComponentSerializer serializer_class = ComponentSerializer

View File

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

View File

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