mirror of
https://gitlab.com/animath/si/plateforme.git
synced 2024-11-30 03:33:03 +00:00
1d81213773
Signed-off-by: Emmy D'Anello <emmy.danello@animath.fr>
52 lines
2.0 KiB
Python
52 lines
2.0 KiB
Python
# Generated by Django 3.2.18 on 2023-02-19 22:13
|
|
from django.contrib.contenttypes.models import ContentType
|
|
from django.db import migrations, models
|
|
from django.db.models import F
|
|
|
|
|
|
def merge_admins(apps, schema_editor):
|
|
AdminRegistration = apps.get_model('registration', 'AdminRegistration')
|
|
VolunteerRegistration = apps.get_model('registration', 'VolunteerRegistration')
|
|
db_alias = schema_editor.connection.alias
|
|
AdminRegistration.objects.using(db_alias).update(admin=True)
|
|
for admin in AdminRegistration.objects.all():
|
|
admin.professional_activity = admin.role
|
|
admin.polymorphic_ctype_id = ContentType.objects.get_for_model(VolunteerRegistration).id
|
|
admin.save()
|
|
|
|
|
|
def separate_admins(apps, schema_editor):
|
|
AdminRegistration = apps.get_model('registration', 'AdminRegistration')
|
|
VolunteerRegistration = apps.get_model('registration', 'VolunteerRegistration')
|
|
for admin in VolunteerRegistration.objects.filter(admin=True).all():
|
|
admin.delete()
|
|
AdminRegistration.objects.create(user=admin.user,
|
|
professional_activity=admin.professional_activity,
|
|
role=admin.professional_activity)
|
|
|
|
|
|
class Migration(migrations.Migration):
|
|
dependencies = [
|
|
('participation', '0003_alter_team_trigram'),
|
|
('registration', '0003_alter_participantregistration_zip_code'),
|
|
]
|
|
|
|
operations = [
|
|
migrations.AddField(
|
|
model_name='volunteerregistration',
|
|
name='admin',
|
|
field=models.BooleanField(
|
|
default=False,
|
|
help_text="An administrator has all rights. Please don't give this right to all juries and volunteers.",
|
|
verbose_name='administrator'),
|
|
),
|
|
migrations.RunPython(
|
|
merge_admins,
|
|
separate_admins,
|
|
elidable=True,
|
|
),
|
|
migrations.DeleteModel(
|
|
name='AdminRegistration',
|
|
),
|
|
]
|