konova/user/migrations/0004_auto_20220530_1105.py
mpeltriaux 170e5798ec #169 Admin on teams
* adds admin column on team index view
* refactors Team model, so multiple members can become admins
* adds team migration for switch from fkey->m2m structure
* renames 'Group' to 'Permission' on user index view to avoid confusion between 'Groups' and Teams
* adds new autocomplete route for team-admin selection based on already selected members of the TeamForm
2022-05-30 14:35:31 +02:00

36 lines
901 B
Python

# Generated by Django 3.1.3 on 2022-05-30 09:05
from django.conf import settings
from django.db import migrations, models
def migrate_fkey_admin_to_m2m(apps, schema_editor):
Team = apps.get_model('user', 'Team')
all_teams = Team.objects.all()
for team in all_teams:
admin = team.admin
if admin is None:
continue
team.admins.add(admin)
team.save()
class Migration(migrations.Migration):
dependencies = [
('user', '0003_team'),
]
operations = [
migrations.AddField(
model_name='team',
name='admins',
field=models.ManyToManyField(blank=True, related_name='_team_admins_+', to=settings.AUTH_USER_MODEL),
),
migrations.RunPython(migrate_fkey_admin_to_m2m),
migrations.RemoveField(
model_name='team',
name='admin',
),
]