mirror of
https://github.com/netbox-community/netbox.git
synced 2025-12-17 17:56:29 +00:00
* 7699 Add Scope to Cluster * 7699 Serializer * 7699 filterset * 7699 bulk_edit * 7699 bulk_import * 7699 model_form * 7699 graphql, tables * 7699 fixes * 7699 fixes * 7699 fixes * 7699 fixes * 7699 fix tests * 7699 fix graphql tests for clusters reference * 7699 fix dcim tests * 7699 fix ipam tests * 7699 fix tests * 7699 use mixin for model * 7699 change mixin name * 7699 scope form * 7699 scope form * 7699 scoped form, fitlerset * 7699 review changes * 7699 move ScopedFilterset * 7699 move CachedScopeMixin * 7699 review changes * 7699 review changes * 7699 refactor mixins * 7699 _sitegroup -> _site_group * 7699 update docstring * Misc cleanup * Update migrations --------- Co-authored-by: Jeremy Stretch <jstretch@netboxlabs.com>
52 lines
1.5 KiB
Python
52 lines
1.5 KiB
Python
import django.db.models.deletion
|
|
from django.db import migrations, models
|
|
|
|
|
|
def copy_site_assignments(apps, schema_editor):
|
|
"""
|
|
Copy site ForeignKey values to the scope GFK.
|
|
"""
|
|
ContentType = apps.get_model('contenttypes', 'ContentType')
|
|
Cluster = apps.get_model('virtualization', 'Cluster')
|
|
Site = apps.get_model('dcim', 'Site')
|
|
|
|
Cluster.objects.filter(site__isnull=False).update(
|
|
scope_type=ContentType.objects.get_for_model(Site),
|
|
scope_id=models.F('site_id')
|
|
)
|
|
|
|
|
|
class Migration(migrations.Migration):
|
|
|
|
dependencies = [
|
|
('contenttypes', '0002_remove_content_type_name'),
|
|
('virtualization', '0043_qinq_svlan'),
|
|
]
|
|
|
|
operations = [
|
|
migrations.AddField(
|
|
model_name='cluster',
|
|
name='scope_id',
|
|
field=models.PositiveBigIntegerField(blank=True, null=True),
|
|
),
|
|
migrations.AddField(
|
|
model_name='cluster',
|
|
name='scope_type',
|
|
field=models.ForeignKey(
|
|
blank=True,
|
|
limit_choices_to=models.Q(('model__in', ('region', 'sitegroup', 'site', 'location'))),
|
|
null=True,
|
|
on_delete=django.db.models.deletion.PROTECT,
|
|
related_name='+',
|
|
to='contenttypes.contenttype',
|
|
),
|
|
),
|
|
|
|
# Copy over existing site assignments
|
|
migrations.RunPython(
|
|
code=copy_site_assignments,
|
|
reverse_code=migrations.RunPython.noop
|
|
),
|
|
|
|
]
|