mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Automatically create UserConfig for users
This commit is contained in:
27
netbox/users/migrations/0005_create_userconfigs.py
Normal file
27
netbox/users/migrations/0005_create_userconfigs.py
Normal file
@@ -0,0 +1,27 @@
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
def create_userconfigs(apps, schema_editor):
|
||||
"""
|
||||
Create an empty UserConfig instance for each existing User.
|
||||
"""
|
||||
User = get_user_model()
|
||||
UserConfig = apps.get_model('users', 'UserConfig')
|
||||
UserConfig.objects.bulk_create(
|
||||
[UserConfig(user_id=user.pk) for user in User.objects.all()]
|
||||
)
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('users', '0004_userconfig'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(
|
||||
code=create_userconfigs,
|
||||
reverse_code=migrations.RunPython.noop
|
||||
),
|
||||
]
|
||||
Reference in New Issue
Block a user