Fix ContentType resolution

This commit is contained in:
Jeremy Stretch 2024-02-28 16:40:57 -05:00
parent cb61ed3277
commit 3d24239b68

View File

@ -10,9 +10,8 @@ def update_custom_fields(apps, schema_editor):
CustomField = apps.get_model('extras', 'CustomField')
Group = apps.get_model('users', 'Group')
old_ct = ContentType.objects.get_by_natural_key('users', 'netboxgroup')
if old_ct := ContentType.objects.filter(app_label='users', model='netboxgroup').first():
new_ct = ContentType.objects.get_for_model(Group)
CustomField.objects.filter(object_type=old_ct).update(object_type=new_ct)
@ -63,10 +62,6 @@ class Migration(migrations.Migration):
field=models.ManyToManyField(blank=True, related_name='object_permissions', to='users.group'),
),
migrations.DeleteModel(
name='NetBoxGroup',
),
# Delete groups from the old table
migrations.RunSQL(
"DELETE from auth_group"
@ -77,4 +72,9 @@ class Migration(migrations.Migration):
code=update_custom_fields,
reverse_code=migrations.RunPython.noop
),
# Delete the proxy model
migrations.DeleteModel(
name='NetBoxGroup',
),
]