add default roles to existing users
This commit is contained in:
22
cookbook/migrations/0036_auto_20200427_1800.py
Normal file
22
cookbook/migrations/0036_auto_20200427_1800.py
Normal file
@ -0,0 +1,22 @@
|
||||
# Generated by Django 3.0.5 on 2020-04-27 16:00
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
def apply_migration(apps, schema_editor):
|
||||
Group = apps.get_model('auth', 'Group')
|
||||
User = apps.get_model('auth', 'User')
|
||||
for u in User.objects.all():
|
||||
if u.groups.count() < 1:
|
||||
u.groups.add(Group.objects.get(name='admin'))
|
||||
u.save()
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
('cookbook', '0035_auto_20200427_1637'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(apply_migration)
|
||||
]
|
@ -1,9 +1,7 @@
|
||||
from django.contrib import messages
|
||||
from django.http import HttpResponse, FileResponse
|
||||
from django.urls import reverse
|
||||
from django.utils.translation import gettext as _
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.http import HttpResponse
|
||||
from django.shortcuts import redirect
|
||||
from django.utils.translation import gettext as _
|
||||
|
||||
from cookbook.helper.permission_helper import group_required
|
||||
from cookbook.models import Recipe, Sync, Storage
|
||||
|
Reference in New Issue
Block a user