diff --git a/InvenTree/part/api.py b/InvenTree/part/api.py index af0e458f47..f3da5ccf40 100644 --- a/InvenTree/part/api.py +++ b/InvenTree/part/api.py @@ -203,10 +203,14 @@ class BomList(generics.ListCreateAPIView): - GET: Return list of BomItem objects - POST: Create a new BomItem object """ - - queryset = BomItem.objects.all() + serializer_class = BomItemSerializer + def get_queryset(self): + queryset = BomItem.objects.all() + queryset = self.get_serializer_class().setup_eager_loading(queryset) + return queryset + permission_classes = [ permissions.IsAuthenticatedOrReadOnly, ] diff --git a/InvenTree/part/serializers.py b/InvenTree/part/serializers.py index a303ea7aa1..9251580bcc 100644 --- a/InvenTree/part/serializers.py +++ b/InvenTree/part/serializers.py @@ -112,16 +112,20 @@ class PartStarSerializer(InvenTreeModelSerializer): class BomItemSerializer(InvenTreeModelSerializer): """ Serializer for BomItem object """ - part_detail = PartBriefSerializer(source='part', many=False, read_only=True) sub_part_detail = PartBriefSerializer(source='sub_part', many=False, read_only=True) price_info = serializers.CharField(read_only=True) + @staticmethod + def setup_eager_loading(queryset): + queryset = queryset.prefetch_related('sub_part') + queryset = queryset.prefetch_related('sub_part__category') + return queryset + class Meta: model = BomItem fields = [ 'pk', 'part', - 'part_detail', 'sub_part', 'sub_part_detail', 'quantity',