2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-08-07 12:22:11 +00:00

Fixed up some stupid recursion on the Tree model template

This commit is contained in:
Oliver Walters
2019-06-18 00:59:54 +10:00
parent 642660d76e
commit 16b6ae8d61
8 changed files with 73 additions and 39 deletions

View File

@@ -35,8 +35,6 @@ class PartCategoryTree(TreeSerializer):
return reverse('part-index')
def get_items(self):
print("hello world")
return PartCategory.objects.all().prefetch_related('parts', 'children')
@@ -112,7 +110,9 @@ class PartList(generics.ListCreateAPIView):
if cat_id:
try:
category = PartCategory.objects.get(pk=cat_id)
parts_list = parts_list.filter(category__in=category.getUniqueChildren())
cats = [category.id]
cats += [cat for cat in category.getUniqueChildren()]
parts_list = parts_list.filter(category__in=cats)
except PartCategory.DoesNotExist:
pass

View File

@@ -0,0 +1,19 @@
# Generated by Django 2.2.2 on 2019-06-17 14:42
import InvenTree.validators
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('part', '0007_auto_20190602_1944'),
]
operations = [
migrations.AlterField(
model_name='partcategory',
name='name',
field=models.CharField(max_length=100, unique=True, validators=[InvenTree.validators.validate_tree_name]),
),
]

View File

@@ -73,10 +73,12 @@ class PartCategory(InvenTreeTree):
(including children of child categories)
"""
cats = [self.id]
if cascade:
query = Part.objects.filter(category__in=self.getUniqueChildren())
else:
query = Part.objects.filter(category=self)
cats += [cat for cat in self.getUniqueChildren()]
query = Part.objects.filter(category__in=cats)
if active:
query = query.filter(active=True)