Skip to content

Commit

Permalink
add migration to automatically assign group to existing superusers
Browse files Browse the repository at this point in the history
  • Loading branch information
vabene1111 committed Apr 6, 2021
1 parent a811d4a commit 0862c0f
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions cookbook/migrations/0118_auto_20210406_1805.py
Original file line number Diff line number Diff line change
@@ -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),
]

0 comments on commit 0862c0f

Please sign in to comment.