2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-07-15 09:21:26 +00:00

Create a custom Manager class for the Part model

- Always perform prefetch_related calls
This commit is contained in:
Oliver
2021-07-20 21:26:51 +10:00
parent d9673244d5
commit 84fc2785d6
2 changed files with 19 additions and 19 deletions

View File

@ -215,25 +215,6 @@ class PartSerializer(InvenTreeModelSerializer):
if category_detail is not True:
self.fields.pop('category_detail')
@staticmethod
def prefetch_queryset(queryset):
"""
Prefetch related database tables,
to reduce database hits.
"""
return queryset.prefetch_related(
'category',
'category__parts',
'category__parent',
'stock_items',
'bom_items',
'builds',
'supplier_parts',
'supplier_parts__purchase_order_line_items',
'supplier_parts__purchase_order_line_items__order',
)
@staticmethod
def annotate_queryset(queryset):
"""