Quellcode durchsuchen

Migrate VLANGroup site assignments

jeremystretch vor 4 Jahren
Ursprung
Commit
7949a5e1fd
1 geänderte Dateien mit 27 neuen und 0 gelöschten Zeilen
  1. 27 0
      netbox/ipam/migrations/0046_set_vlangroup_scope_types.py

+ 27 - 0
netbox/ipam/migrations/0046_set_vlangroup_scope_types.py

@@ -0,0 +1,27 @@
+from django.db import migrations
+
+
+def set_scope_types(apps, schema_editor):
+    """
+    Set 'site' as the scope type for all VLANGroups with a scope ID defined.
+    """
+    ContentType = apps.get_model('contenttypes', 'ContentType')
+    VLANGroup = apps.get_model('ipam', 'VLANGroup')
+
+    site_ct = ContentType.objects.get(app_label='dcim', model='site').pk
+    VLANGroup.objects.filter(scope_id__isnull=False).update(
+        scope_type=site_ct
+    )
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('ipam', '0045_vlangroup_scope'),
+    ]
+
+    operations = [
+        migrations.RunPython(
+            code=set_scope_types
+        ),
+    ]