Skip to content

Commit 905d172

Browse files
committed
Review feedback
1 parent 44e5a4c commit 905d172

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

netbox/dcim/migrations/0226_modulebay_rebuild_tree.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,23 @@
11
from django.db import migrations
22
import mptt.managers
3+
import mptt.models
34

45

56
def rebuild_mptt(apps, schema_editor):
6-
manager = mptt.managers.TreeManager()
7+
"""
8+
Rebuild the MPTT tree for ModuleBay to apply new ordering.
9+
"""
710
ModuleBay = apps.get_model('dcim', 'ModuleBay')
11+
12+
# Set MPTTMeta with the correct order_insertion_by
13+
class MPTTMeta:
14+
order_insertion_by = ('module', 'name',)
15+
16+
ModuleBay.MPTTMeta = MPTTMeta
17+
ModuleBay._mptt_meta = mptt.models.MPTTOptions(MPTTMeta)
18+
19+
manager = mptt.managers.TreeManager()
820
manager.model = ModuleBay
9-
mptt.register(ModuleBay)
1021
manager.contribute_to_class(ModuleBay, 'objects')
1122
manager.rebuild()
1223

0 commit comments

Comments
 (0)