mirror of
https://github.com/inventree/InvenTree.git
synced 2025-08-10 05:40:55 +00:00
Reduced tree time with some better queries
This commit is contained in:
@@ -69,13 +69,20 @@ class PartCategory(InvenTreeTree):
|
||||
return self.partcount
|
||||
|
||||
@property
|
||||
def partcount(self):
|
||||
def partcount(self, cascade=True, active=True):
|
||||
""" Return the total part count under this category
|
||||
(including children of child categories)
|
||||
"""
|
||||
|
||||
return len(Part.objects.filter(category__in=self.getUniqueChildren(),
|
||||
active=True))
|
||||
if cascade:
|
||||
query = Part.objects.filter(category__in=self.getUniqueChildren())
|
||||
else:
|
||||
query = Part.objects.filter(category=self)
|
||||
|
||||
if active:
|
||||
query = query.filter(active=True)
|
||||
|
||||
return query.count()
|
||||
|
||||
@property
|
||||
def has_parts(self):
|
||||
|
Reference in New Issue
Block a user