Skip to content

Commit 0ec632e

Browse files
authored
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
1 parent cc6f21d commit 0ec632e

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from django.db import migrations
2+
import mptt
3+
import mptt.managers
4+
5+
6+
def rebuild_mptt(apps, schema_editor):
7+
manager = mptt.managers.TreeManager()
8+
ModuleBay = apps.get_model('dcim', 'ModuleBay')
9+
manager.model = ModuleBay
10+
mptt.register(ModuleBay)
11+
manager.contribute_to_class(ModuleBay, 'objects')
12+
manager.rebuild()
13+
14+
15+
class Migration(migrations.Migration):
16+
17+
dependencies = [
18+
('dcim', '0190_nested_modules'),
19+
]
20+
21+
operations = [
22+
migrations.RunPython(
23+
code=rebuild_mptt,
24+
reverse_code=migrations.RunPython.noop
25+
),
26+
]

0 commit comments

Comments
 (0)