Filtering improvements

This commit is contained in:
Oliver Walters 2017-04-16 14:24:15 +10:00
parent 883efd0945
commit 057fd1dd20
7 changed files with 15 additions and 39 deletions

View File

@ -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

View File

@ -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()

View File

@ -11,6 +11,7 @@ class StockItemSerializer(serializers.HyperlinkedModelSerializer):
model = StockItem
fields = ('url',
'part',
'supplier_part',
'location',
'quantity',
'status',

View File

@ -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']

View File

@ -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']

View File

@ -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):

View File

@ -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