0074_auto_20180629_1717.py 1.43 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
# -*- coding: utf-8 -*-
# Generated by Django 1.10.7 on 2018-06-29 15:17
from __future__ import unicode_literals

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

    dependencies = [
        ('users', '0073_auto_20180629_1614'),
    ]

16 17 18 19 20 21 22 23 24 25 26 27 28
    def transfer_pseudo(apps, schema_editor):
        db_alias = schema_editor.connection.alias
        users = apps.get_model("users", "User")
        mailalias = apps.get_model("users", "MailAlias")
        users_list = users.objects.using(db_alias).all()
        for user in users_list:
            mailalias.objects.using(db_alias).create(valeur=user.pseudo, user=user)

    def untransfer_pseudo(apps, schema_editor):
        db_alias = schema_editor.connection.alias
        mailalias = apps.get_model("users", "MailAlias")
        mailalias.objects.using(db_alias).delete()

29 30 31 32 33 34 35 36 37
    operations = [
        migrations.AlterField(
            model_name='mailalias',
            name='user',
            field=models.ForeignKey(help_text='Utilisateur associé', on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL),
        ),
        migrations.AlterField(
            model_name='mailalias',
            name='valeur',
38
            field=models.CharField(help_text="Valeur de l'alias mail", max_length=128, unique=True),
39
        ),
40
        migrations.RunPython(transfer_pseudo, untransfer_pseudo),
41
    ]