-
-
Notifications
You must be signed in to change notification settings - Fork 615
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add migration to automatically assign group to existing superusers
- Loading branch information
1 parent
a811d4a
commit 0862c0f
Showing
1 changed file
with
25 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
] |