2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-12-16 17:28:11 +00:00

[refactor] Build list (#11010)

- Prefetch project_code
- Annotate parameter data
This commit is contained in:
Oliver
2025-12-14 19:09:01 +11:00
committed by GitHub
parent 9c6d16baba
commit 0460e81f9a
2 changed files with 5 additions and 10 deletions

View File

@@ -317,14 +317,15 @@ class BuildMixin:
"""Return the queryset for the Build API endpoints.""" """Return the queryset for the Build API endpoints."""
queryset = super().get_queryset() queryset = super().get_queryset()
queryset = build.serializers.BuildSerializer.annotate_queryset(queryset)
queryset = queryset.prefetch_related( queryset = queryset.prefetch_related(
'responsible', 'responsible',
'issued_by', 'issued_by',
'build_lines', 'build_lines',
'build_lines__bom_item',
'build_lines__build',
'part', 'part',
'part__pricing_data', 'part__pricing_data',
'project_code',
) )
return queryset return queryset
@@ -384,14 +385,6 @@ class BuildList(
'priority', 'priority',
] ]
def get_queryset(self):
"""Override the queryset filtering, as some of the fields don't natively play nicely with DRF."""
queryset = super().get_queryset().select_related('part')
queryset = build.serializers.BuildSerializer.annotate_queryset(queryset)
return queryset
def get_serializer(self, *args, **kwargs): def get_serializer(self, *args, **kwargs):
"""Add extra context information to the endpoint serializer.""" """Add extra context information to the endpoint serializer."""
kwargs['create'] = True kwargs['create'] = True

View File

@@ -192,6 +192,8 @@ class BuildSerializer(
) )
) )
queryset = Build.annotate_parameters(queryset)
return queryset return queryset
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):