mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Merge pull request #1812 from eeintech/improve_supplier_part_fetch
Custom SupplierPart object manager and prefetch related models
This commit is contained in:
commit
c816afbe62
@ -263,11 +263,7 @@ class SupplierPartList(generics.ListCreateAPIView):
|
|||||||
- POST: Create a new SupplierPart object
|
- POST: Create a new SupplierPart object
|
||||||
"""
|
"""
|
||||||
|
|
||||||
queryset = SupplierPart.objects.all().prefetch_related(
|
queryset = SupplierPart.objects.all()
|
||||||
'part',
|
|
||||||
'supplier',
|
|
||||||
'manufacturer_part__manufacturer',
|
|
||||||
)
|
|
||||||
|
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
|
|
||||||
|
@ -430,6 +430,22 @@ class ManufacturerPartParameter(models.Model):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class SupplierPartManager(models.Manager):
|
||||||
|
""" Define custom SupplierPart objects manager
|
||||||
|
|
||||||
|
The main purpose of this manager is to improve database hit as the
|
||||||
|
SupplierPart model involves A LOT of foreign keys lookups
|
||||||
|
"""
|
||||||
|
|
||||||
|
def get_queryset(self):
|
||||||
|
# Always prefetch related models
|
||||||
|
return super().get_queryset().prefetch_related(
|
||||||
|
'part',
|
||||||
|
'supplier',
|
||||||
|
'manufacturer_part__manufacturer',
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class SupplierPart(models.Model):
|
class SupplierPart(models.Model):
|
||||||
""" Represents a unique part as provided by a Supplier
|
""" Represents a unique part as provided by a Supplier
|
||||||
Each SupplierPart is identified by a SKU (Supplier Part Number)
|
Each SupplierPart is identified by a SKU (Supplier Part Number)
|
||||||
@ -450,6 +466,8 @@ class SupplierPart(models.Model):
|
|||||||
packaging: packaging that the part is supplied in, e.g. "Reel"
|
packaging: packaging that the part is supplied in, e.g. "Reel"
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
objects = SupplierPartManager()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_api_url():
|
def get_api_url():
|
||||||
return reverse('api-supplier-part-list')
|
return reverse('api-supplier-part-list')
|
||||||
|
@ -15,6 +15,7 @@ from .models import SalesOrderAllocation
|
|||||||
|
|
||||||
class PurchaseOrderLineItemInlineAdmin(admin.StackedInline):
|
class PurchaseOrderLineItemInlineAdmin(admin.StackedInline):
|
||||||
model = PurchaseOrderLineItem
|
model = PurchaseOrderLineItem
|
||||||
|
extra = 0
|
||||||
|
|
||||||
|
|
||||||
class PurchaseOrderAdmin(ImportExportModelAdmin):
|
class PurchaseOrderAdmin(ImportExportModelAdmin):
|
||||||
|
Loading…
Reference in New Issue
Block a user