8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-25 22:22:26 +00:00

Initialise les alias pour les bases existantes

This commit is contained in:
chirac 2018-06-29 19:28:55 +02:00 committed by Maël Kervella
parent da87579f81
commit 98a95da9a0

View file

@ -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=128, unique=True),
),
migrations.RunPython(transfer_pseudo, untransfer_pseudo),
]