mirror of
https://github.com/netbox-community/netbox.git
synced 2026-01-22 03:28:45 -06:00
add migration
This commit is contained in:
26
netbox/dcim/migrations/0226_modulebay_rebuild_tree.py
Normal file
26
netbox/dcim/migrations/0226_modulebay_rebuild_tree.py
Normal file
@@ -0,0 +1,26 @@
|
||||
from django.db import migrations
|
||||
import mptt
|
||||
import mptt.managers
|
||||
|
||||
|
||||
def rebuild_mptt(apps, schema_editor):
|
||||
"""
|
||||
Rebuild the MPTT tree for ModuleBay to apply new ordering by 'name'
|
||||
instead of 'module'.
|
||||
"""
|
||||
manager = mptt.managers.TreeManager()
|
||||
ModuleBay = apps.get_model('dcim', 'ModuleBay')
|
||||
manager.model = ModuleBay
|
||||
mptt.register(ModuleBay)
|
||||
manager.contribute_to_class(ModuleBay, 'objects')
|
||||
manager.rebuild()
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
('dcim', '0225_gfk_indexes'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(code=rebuild_mptt, reverse_code=migrations.RunPython.noop),
|
||||
]
|
||||
Reference in New Issue
Block a user