|
@@ -1,12 +1,23 @@
|
|
|
from django.db import migrations
|
|
from django.db import migrations
|
|
|
import mptt.managers
|
|
import mptt.managers
|
|
|
|
|
+import mptt.models
|
|
|
|
|
|
|
|
|
|
|
|
|
def rebuild_mptt(apps, schema_editor):
|
|
def rebuild_mptt(apps, schema_editor):
|
|
|
- manager = mptt.managers.TreeManager()
|
|
|
|
|
|
|
+ """
|
|
|
|
|
+ Rebuild the MPTT tree for ModuleBay to apply new ordering.
|
|
|
|
|
+ """
|
|
|
ModuleBay = apps.get_model('dcim', 'ModuleBay')
|
|
ModuleBay = apps.get_model('dcim', 'ModuleBay')
|
|
|
|
|
+
|
|
|
|
|
+ # Set MPTTMeta with the correct order_insertion_by
|
|
|
|
|
+ class MPTTMeta:
|
|
|
|
|
+ order_insertion_by = ('module', 'name',)
|
|
|
|
|
+
|
|
|
|
|
+ ModuleBay.MPTTMeta = MPTTMeta
|
|
|
|
|
+ ModuleBay._mptt_meta = mptt.models.MPTTOptions(MPTTMeta)
|
|
|
|
|
+
|
|
|
|
|
+ manager = mptt.managers.TreeManager()
|
|
|
manager.model = ModuleBay
|
|
manager.model = ModuleBay
|
|
|
- mptt.register(ModuleBay)
|
|
|
|
|
manager.contribute_to_class(ModuleBay, 'objects')
|
|
manager.contribute_to_class(ModuleBay, 'objects')
|
|
|
manager.rebuild()
|
|
manager.rebuild()
|
|
|
|
|
|