1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00
netbox-community-netbox/netbox/users/migrations/0005_alter_user_table.py
Arthur Hanson 317bef6796 12795 custom user model (#15005)
* 12795 users.User migration

* 12795 users.User migration

* 12795 review changes

* 12795 fix user model registration

* 12795 fix user model registration

* 12795 update migration

* 12795 update migration

* 12795 update migration

* 12795 add comment to migration db_table

* Tweak import to avoid class name collision

* 12795 add comment for _register_features requirement

---------

Co-authored-by: Jeremy Stretch <jstretch@netboxlabs.com>
2024-02-05 13:24:03 -05:00

41 lines
1.4 KiB
Python

# Generated by Django 5.0.1 on 2024-01-31 23:18
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 users app
ContentType.objects.filter(app_label='users', model='user').delete()
# Update the app labels of the original ContentTypes for auth.User to ensure
# that any foreign key references are preserved
ContentType.objects.filter(app_label='auth', model='user').update(app_label='users')
netboxuser_ct = ContentType.objects.filter(app_label='users', model='netboxuser').first()
if netboxuser_ct:
user_ct = ContentType.objects.filter(app_label='users', model='user').first()
CustomField = apps.get_model('extras', 'CustomField')
CustomField.objects.filter(object_type_id=netboxuser_ct.id).update(object_type_id=user_ct.id)
netboxuser_ct.delete()
class Migration(migrations.Migration):
dependencies = [
('users', '0002_squashed_0004'),
]
operations = [
# 0001_squashed had model with db_table=auth_user - now we switch it
# to None to use the default Django resolution (users.user)
migrations.AlterModelTable(
name='user',
table=None,
),
migrations.RunPython(
code=update_content_types,
reverse_code=migrations.RunPython.noop
),
]