add migration to automatically assign group to existing superusers
This commit is contained in:
parent
a811d4a55c
commit
0862c0f0bc
25
cookbook/migrations/0118_auto_20210406_1805.py
Normal file
25
cookbook/migrations/0118_auto_20210406_1805.py
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
# Generated by Django 3.1.7 on 2021-04-06 16:05
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
from django_scopes import scopes_disabled
|
||||||
|
|
||||||
|
|
||||||
|
def migrate_no_group_superusers(apps, schema_editor):
|
||||||
|
with scopes_disabled():
|
||||||
|
User = apps.get_model('auth', 'User')
|
||||||
|
Groups = apps.get_model('auth', 'Group')
|
||||||
|
|
||||||
|
for u in User.objects.filter(is_superuser=True).all():
|
||||||
|
if u.groups.count() == 0:
|
||||||
|
u.groups.add(Groups.objects.get(name='admin'))
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('cookbook', '0117_space_max_recipes'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RunPython(migrate_no_group_superusers),
|
||||||
|
]
|
Loading…
Reference in New Issue
Block a user