Added filtering to REST interfaces

This commit is contained in:
Dirk Jahnke 2022-04-14 18:15:55 +02:00
parent 8cc1e7d8ad
commit e04c435f87
2 changed files with 8 additions and 1 deletions

View File

@ -13,6 +13,7 @@ class ContainerViewSet(viewsets.ModelViewSet):
queryset = Container.objects.all().order_by('named_id')
serializer_class = ContainerSerializer
permission_classes = [permissions.IsAuthenticated]
filterset_fields = ['named_id', 'color']
class ContainerTypeViewSet(viewsets.ModelViewSet):
@ -22,6 +23,7 @@ class ContainerTypeViewSet(viewsets.ModelViewSet):
queryset = ContainerType.objects.all()
serializer_class = ContainerTypeSerializer
permission_classes = [permissions.IsAuthenticated]
filterset_fields = ['named_id', 'has_cover', 'contains_container']
class AssetViewSet(viewsets.ModelViewSet):
@ -31,6 +33,8 @@ class AssetViewSet(viewsets.ModelViewSet):
queryset = Asset.objects.all().order_by('named_id')
serializer_class = AssetSerializer
permission_classes = [permissions.IsAuthenticated]
filterset_fields = ['named_id', 'quantity']
class GtinProductViewSet(viewsets.ModelViewSet):
@ -40,3 +44,5 @@ class GtinProductViewSet(viewsets.ModelViewSet):
queryset = GtinProduct.objects.all().order_by('gtin')
serializer_class = GtinProductSerializer
permission_classes = [permissions.IsAuthenticated]
filterset_fields = ['gtin']

View File

@ -176,5 +176,6 @@ REST_FRAMEWORK = {
'rest_framework.permissions.DjangoModelPermissionsOrAnonReadOnly'
],
'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',
'PAGE_SIZE': 10
'PAGE_SIZE': 10,
'DEFAULT_FILTER_BACKENDS': ['django_filters.rest_framework.DjangoFilterBackend']
}