Extend migration to update content types

This commit is contained in:
Jeremy Stretch 2023-11-28 07:59:12 -05:00
parent 0195c06863
commit 6a7d909757

View File

@ -1,6 +1,19 @@
from django.db import migrations from django.db import migrations
def update_content_types(apps, schema_editor):
ContentType = apps.get_model('contenttypes', 'ContentType')
# Delete the new ContentTypes effected by the new models in the vpn app
ContentType.objects.filter(app_label='vpn', model='l2vpn').delete()
ContentType.objects.filter(app_label='vpn', model='l2vpntermination').delete()
# Update the app labels of the original ContentTypes for ipam.L2VPN and ipam.L2VPNTermination to ensure
# that any foreign key references are preserved
ContentType.objects.filter(app_label='ipam', model='l2vpn').update(app_label='vpn')
ContentType.objects.filter(app_label='ipam', model='l2vpntermination').update(app_label='vpn')
class Migration(migrations.Migration): class Migration(migrations.Migration):
dependencies = [ dependencies = [
@ -44,4 +57,8 @@ class Migration(migrations.Migration):
), ),
], ],
), ),
migrations.RunPython(
code=update_content_types,
reverse_code=migrations.RunPython.noop
),
] ]