From f83f9e53a6bad3f4d2cf35cb4281f51e17c8539e Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Wed, 2 Aug 2023 09:35:41 -0400 Subject: [PATCH] Update references to device_role column in UserConfigs --- .../0181_rename_device_role_device_role.py | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/netbox/dcim/migrations/0181_rename_device_role_device_role.py b/netbox/dcim/migrations/0181_rename_device_role_device_role.py index 706213692..e32e00221 100644 --- a/netbox/dcim/migrations/0181_rename_device_role_device_role.py +++ b/netbox/dcim/migrations/0181_rename_device_role_device_role.py @@ -1,8 +1,21 @@ -# Generated by Django 4.1.10 on 2023-08-02 06:59 - from django.db import migrations +def update_table_configs(apps, schema_editor): + """ + Replace the `device_role` column in DeviceTable configs with `role`. + """ + UserConfig = apps.get_model('users', 'UserConfig') + + for table in ('DeviceTable', 'DeviceBayTable'): + for config in UserConfig.objects.filter(**{f'data__tables__{table}__columns__contains': 'device_role'}): + config.data['tables'][table]['columns'] = [ + 'role' if x == 'device_role' else x + for x in config.data['tables'][table]['columns'] + ] + config.save() + + class Migration(migrations.Migration): dependencies = [ @@ -15,4 +28,8 @@ class Migration(migrations.Migration): old_name='device_role', new_name='role', ), + migrations.RunPython( + code=update_table_configs, + reverse_code=migrations.RunPython.noop + ), ]