2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-04-29 12:06:44 +00:00

Simplify part filtering

This commit is contained in:
Oliver Walters 2019-04-15 22:39:28 +10:00
parent 7e78f0aa67
commit ac0b28a06c

View File

@ -70,13 +70,14 @@ class PartList(generics.ListCreateAPIView):
serializer_class = PartSerializer serializer_class = PartSerializer
def get_queryset(self): def get_queryset(self):
print("Get queryset")
# Does the user wish to filter by category? # Does the user wish to filter by category?
cat_id = self.request.query_params.get('category', None) cat_id = self.request.query_params.get('category', None)
# Start with all objects
parts_list = Part.objects.all()
if cat_id: if cat_id:
print("Getting category:", cat_id)
category = get_object_or_404(PartCategory, pk=cat_id) category = get_object_or_404(PartCategory, pk=cat_id)
# Filter by the supplied category # Filter by the supplied category
@ -90,10 +91,10 @@ class PartList(generics.ListCreateAPIView):
continue continue
flt |= Q(category=child) flt |= Q(category=child)
return Part.objects.filter(flt) parts_list = parts_list.filter(flt)
# Default - return all parts # Default - return all parts
return Part.objects.all() return parts_list
permission_classes = [ permission_classes = [
permissions.IsAuthenticatedOrReadOnly, permissions.IsAuthenticatedOrReadOnly,