mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-29 12:06:44 +00:00
Add 'include self' option to getUniqueChildren
This commit is contained in:
parent
16b6ae8d61
commit
37dba91b4a
@ -80,7 +80,7 @@ class InvenTreeTree(models.Model):
|
|||||||
|
|
||||||
return unique
|
return unique
|
||||||
|
|
||||||
def getUniqueChildren(self, unique=None):
|
def getUniqueChildren(self, unique=None, include_self=False):
|
||||||
""" Return a flat set of all child items that exist under this node.
|
""" Return a flat set of all child items that exist under this node.
|
||||||
If any child items are repeated, the repetitions are omitted.
|
If any child items are repeated, the repetitions are omitted.
|
||||||
"""
|
"""
|
||||||
@ -88,6 +88,9 @@ class InvenTreeTree(models.Model):
|
|||||||
if unique is None:
|
if unique is None:
|
||||||
unique = set()
|
unique = set()
|
||||||
|
|
||||||
|
if include_self:
|
||||||
|
unique.add(self.id)
|
||||||
|
|
||||||
if self.id in unique:
|
if self.id in unique:
|
||||||
return unique
|
return unique
|
||||||
|
|
||||||
|
@ -110,8 +110,7 @@ class PartList(generics.ListCreateAPIView):
|
|||||||
if cat_id:
|
if cat_id:
|
||||||
try:
|
try:
|
||||||
category = PartCategory.objects.get(pk=cat_id)
|
category = PartCategory.objects.get(pk=cat_id)
|
||||||
cats = [category.id]
|
cats = category.getUniqueChildren(include_self=True)
|
||||||
cats += [cat for cat in category.getUniqueChildren()]
|
|
||||||
parts_list = parts_list.filter(category__in=cats)
|
parts_list = parts_list.filter(category__in=cats)
|
||||||
except PartCategory.DoesNotExist:
|
except PartCategory.DoesNotExist:
|
||||||
pass
|
pass
|
||||||
|
Loading…
x
Reference in New Issue
Block a user