Coverage for src/backend/InvenTree/part/migrations/0083_auto_20220731_2357.py: 40%
19 statements
« prev ^ index » next coverage.py v7.15.2, created at 2026-10-07 17:47 +0000
« prev ^ index » next coverage.py v7.15.2, created at 2026-10-07 17:47 +0000
1# Generated by Django 3.2.14 on 2022-07-31 23:57
3from django.db import migrations
5from InvenTree.helpers import constructPathString
8def update_pathstring(apps, schema_editor):
9 """Construct pathstring for all existing PartCategory objects"""
11 PartCategory = apps.get_model('part', 'partcategory')
13 n = PartCategory.objects.count()
15 if n > 0: 15 ↛ 17line 15 didn't jump to line 17 because the condition on line 15 was never true
17 for cat in PartCategory.objects.all():
19 # Construct complete path for category
20 path = [cat.name]
22 parent = cat.parent
24 # Iterate up the tree
25 while parent is not None:
26 path = [parent.name] + path
27 parent = parent.parent
29 pathstring = constructPathString(path)
31 cat.pathstring = pathstring
32 cat.save()
34 print(f"\n--- Updated 'pathstring' for {n} PartCategory objects ---\n")
37class Migration(migrations.Migration):
39 dependencies = [
40 ('part', '0082_partcategory_pathstring'),
41 ]
43 operations = [
44 migrations.RunPython(
45 update_pathstring,
46 reverse_code=migrations.RunPython.noop
47 )
48 ]