From bee0a519ef71b6e778ad56ae5b0e971ceac46104 Mon Sep 17 00:00:00 2001 From: Oliver Date: Wed, 21 Jul 2021 21:18:01 +1000 Subject: [PATCH] Allow filtering of PartList by exclude_tree --- InvenTree/part/api.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/InvenTree/part/api.py b/InvenTree/part/api.py index 39801070c7..527a9395ee 100644 --- a/InvenTree/part/api.py +++ b/InvenTree/part/api.py @@ -644,6 +644,20 @@ class PartList(generics.ListCreateAPIView): except (ValueError, Part.DoesNotExist): pass + # Exclude part variant tree? + exclude_tree = params.get('exclude_tree', None) + + if exclude_tree is not None: + try: + top_level_part = Part.objects.get(pk=exclude_tree) + + queryset = queryset.exclude( + pk__in=[prt.pk for prt in top_level_part.get_descendants(include_self=True)] + ) + + except (ValueError, Part.DoesNotExist): + pass + # Filter by 'ancestor'? ancestor = params.get('ancestor', None)