From ab42b0016457b7893075d5eb7f2054627d4b8291 Mon Sep 17 00:00:00 2001 From: Arthur Hanson Date: Thu, 26 Sep 2024 12:24:32 -0700 Subject: [PATCH] 17419 fix MPTT issue with migrations for nested module bays (#17553) * 17419 rebuild module bay tree on upgrade * 17419 rebuild module bay tree on upgrade * 17419 use get_model --- .../migrations/0191_module_bay_rebuild.py | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 netbox/dcim/migrations/0191_module_bay_rebuild.py diff --git a/netbox/dcim/migrations/0191_module_bay_rebuild.py b/netbox/dcim/migrations/0191_module_bay_rebuild.py new file mode 100644 index 00000000000..2600632131f --- /dev/null +++ b/netbox/dcim/migrations/0191_module_bay_rebuild.py @@ -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 + ), + ]