From 081ae1e8ddd85b603b3275ef7266deb6d8dd5c7c Mon Sep 17 00:00:00 2001 From: chirac Date: Fri, 29 Jun 2018 19:28:55 +0200 Subject: [PATCH] Initialise les alias pour les bases existantes --- users/migrations/0074_auto_20180629_1717.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/users/migrations/0074_auto_20180629_1717.py b/users/migrations/0074_auto_20180629_1717.py index 446a2cdd..92c53a90 100644 --- a/users/migrations/0074_auto_20180629_1717.py +++ b/users/migrations/0074_auto_20180629_1717.py @@ -13,6 +13,19 @@ class Migration(migrations.Migration): ('users', '0073_auto_20180629_1614'), ] + 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() + operations = [ migrations.AlterField( model_name='mailalias', @@ -24,4 +37,5 @@ class Migration(migrations.Migration): name='valeur', field=models.CharField(help_text="Valeur de l'alias mail", max_length=64, unique=True), ), + migrations.RunPython(transfer_pseudo, untransfer_pseudo), ]