We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 44e5a4c commit 905d172Copy full SHA for 905d172
netbox/dcim/migrations/0226_modulebay_rebuild_tree.py
@@ -1,12 +1,23 @@
1
from django.db import migrations
2
import mptt.managers
3
+import mptt.models
4
5
6
def rebuild_mptt(apps, schema_editor):
- manager = mptt.managers.TreeManager()
7
+ """
8
+ Rebuild the MPTT tree for ModuleBay to apply new ordering.
9
10
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()
20
manager.model = ModuleBay
- mptt.register(ModuleBay)
21
manager.contribute_to_class(ModuleBay, 'objects')
22
manager.rebuild()
23
0 commit comments