From 057fd1dd20eb3cb2000d3fd270bcff9f2e4dc538 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sun, 16 Apr 2017 14:24:15 +1000 Subject: [PATCH] Filtering improvements --- InvenTree/part/views.py | 3 --- InvenTree/project/views.py | 26 +++++++++++++------------- InvenTree/stock/serializers.py | 1 + InvenTree/stock/views.py | 6 ------ InvenTree/supplier/views.py | 8 -------- InvenTree/track/serializers.py | 5 +---- InvenTree/track/views.py | 5 ----- 7 files changed, 15 insertions(+), 39 deletions(-) diff --git a/InvenTree/part/views.py b/InvenTree/part/views.py index 40c7134860..a77638c753 100644 --- a/InvenTree/part/views.py +++ b/InvenTree/part/views.py @@ -31,8 +31,6 @@ class PartDetail(generics.RetrieveUpdateDestroyAPIView): class PartParamFilter(FilterSet): - part = NumberFilter(name='part', lookup_expr='exact') - class Meta: model = PartParameter fields = ['part'] @@ -75,7 +73,6 @@ class PartParamDetail(generics.RetrieveUpdateDestroyAPIView): class PartFilter(FilterSet): - category = NumberFilter(name='category', lookup_expr='exact') class Meta: model = Part diff --git a/InvenTree/project/views.py b/InvenTree/project/views.py index 2a293a0cca..593407ae63 100644 --- a/InvenTree/project/views.py +++ b/InvenTree/project/views.py @@ -1,5 +1,6 @@ -from rest_framework import generics, permissions +from django_filters.rest_framework import FilterSet, DjangoFilterBackend +from rest_framework import generics, permissions from InvenTree.models import FilterChildren from .models import ProjectCategory, Project, ProjectPart from .serializers import ProjectSerializer @@ -26,6 +27,13 @@ class ProjectDetail(generics.RetrieveUpdateDestroyAPIView): permission_classes = (permissions.IsAuthenticatedOrReadOnly,) +class ProjectFilter(FilterSet): + + class Meta: + model = Project + fields = ['category'] + + class ProjectList(generics.ListCreateAPIView): """ @@ -38,19 +46,11 @@ class ProjectList(generics.ListCreateAPIView): """ - def get_queryset(self): - projects = Project.objects.all() - params = self.request.query_params - - cat_id = params.get('category', None) - - if cat_id: - projects = projects.filter(category=cat_id) - - return projects - + queryset = Project.objects.all() serializer_class = ProjectSerializer permission_classes = (permissions.IsAuthenticatedOrReadOnly,) + filter_backends = (DjangoFilterBackend,) + filter_class = ProjectFilter class ProjectCategoryDetail(generics.RetrieveUpdateAPIView): @@ -136,7 +136,7 @@ class ProjectPartDetail(generics.RetrieveUpdateDestroyAPIView): delete: Remove a ProjectPart - + """ queryset = ProjectPart.objects.all() diff --git a/InvenTree/stock/serializers.py b/InvenTree/stock/serializers.py index 99db85e2ec..f0ba1c805d 100644 --- a/InvenTree/stock/serializers.py +++ b/InvenTree/stock/serializers.py @@ -11,6 +11,7 @@ class StockItemSerializer(serializers.HyperlinkedModelSerializer): model = StockItem fields = ('url', 'part', + 'supplier_part', 'location', 'quantity', 'status', diff --git a/InvenTree/stock/views.py b/InvenTree/stock/views.py index 026c9084ab..a0a9cf4beb 100644 --- a/InvenTree/stock/views.py +++ b/InvenTree/stock/views.py @@ -29,8 +29,6 @@ class StockDetail(generics.RetrieveUpdateDestroyAPIView): class StockFilter(FilterSet): min_stock = NumberFilter(name='quantity', lookup_expr='gte') max_stock = NumberFilter(name='quantity', lookup_expr='lte') - part = NumberFilter(name='part', lookup_expr='exact') - location = NumberFilter(name='location', lookup_expr='exact') class Meta: model = StockItem @@ -76,8 +74,6 @@ class LocationDetail(generics.RetrieveUpdateDestroyAPIView): class StockLocationFilter(FilterSet): - parent = NumberFilter(name='parent', lookup_expr='exact') - class Meta: model = StockLocation fields = ['parent'] @@ -123,8 +119,6 @@ class StockTrackingDetail(generics.RetrieveUpdateDestroyAPIView): class StockTrackingFilter(FilterSet): - item = NumberFilter(name='item', lookup_expr='exact') - class Meta: model = StockTracking fields = ['item'] diff --git a/InvenTree/supplier/views.py b/InvenTree/supplier/views.py index ac8995de48..aed416f56b 100644 --- a/InvenTree/supplier/views.py +++ b/InvenTree/supplier/views.py @@ -138,12 +138,6 @@ class SupplierPartDetail(generics.RetrieveUpdateDestroyAPIView): class SupplierPartFilter(FilterSet): - supplier = NumberFilter(name='supplier', lookup_expr='exact') - - part = NumberFilter(name='part', lookup_expr='exact') - - manufacturer = NumberFilter(name='manufacturer', lookup_expr='exact') - class Meta: model = SupplierPart fields = ['supplier', 'part', 'manufacturer'] @@ -190,8 +184,6 @@ class SupplierPriceBreakDetail(generics.RetrieveUpdateDestroyAPIView): class PriceBreakFilter(FilterSet): - part = NumberFilter(name='part', lookup_expr='exact') - class Meta: model = SupplierPriceBreak fields = ['part'] diff --git a/InvenTree/track/serializers.py b/InvenTree/track/serializers.py index c2c097c28d..34f15e227d 100644 --- a/InvenTree/track/serializers.py +++ b/InvenTree/track/serializers.py @@ -5,8 +5,6 @@ from .models import UniquePart, PartTrackingInfo class UniquePartSerializer(serializers.HyperlinkedModelSerializer): - tracking_info = serializers.PrimaryKeyRelatedField(many=True, read_only=True) - class Meta: model = UniquePart fields = ['url', @@ -15,8 +13,7 @@ class UniquePartSerializer(serializers.HyperlinkedModelSerializer): 'serial', # 'createdBy', 'customer', - 'status', - 'tracking_info'] + 'status'] class PartTrackingInfoSerializer(serializers.HyperlinkedModelSerializer): diff --git a/InvenTree/track/views.py b/InvenTree/track/views.py index f45205993d..c36f710e0d 100644 --- a/InvenTree/track/views.py +++ b/InvenTree/track/views.py @@ -31,10 +31,6 @@ class UniquePartFilter(FilterSet): min_sn = NumberFilter(name='serial', lookup_expr='gte') max_sn = NumberFilter(name='serial', lookup_expr='lte') - sn = NumberFilter(name='serial', lookup_expr='exact') - part = NumberFilter(name='part', lookup_expr='exact') - customer = NumberFilter(name='customer', lookup_expr='exact') - class Meta: model = UniquePart fields = ['serial', 'part', 'customer'] @@ -77,7 +73,6 @@ class PartTrackingDetail(generics.RetrieveUpdateDestroyAPIView): class PartTrackingFilter(FilterSet): - part = NumberFilter(name='part', lookup_expr='exact') class Meta: model = PartTrackingInfo