Skip to content

Commit

Permalink
17419 fix MPTT issue with migrations for nested module bays (#17553)
Browse files Browse the repository at this point in the history
* 17419 rebuild module bay tree on upgrade

* 17419 rebuild module bay tree on upgrade

* 17419 use get_model
  • Loading branch information
arthanson authored and bctiemann committed Oct 11, 2024
1 parent 2cae87f commit ab42b00
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions netbox/dcim/migrations/0191_module_bay_rebuild.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from django.db import migrations
import mptt
import mptt.managers


def rebuild_mptt(apps, schema_editor):
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', '0190_nested_modules'),
]

operations = [
migrations.RunPython(
code=rebuild_mptt,
reverse_code=migrations.RunPython.noop
),
]

0 comments on commit ab42b00

Please sign in to comment.