mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-22 11:23:10 +00:00
Initialise les alias pour les bases existantes
This commit is contained in:
parent
da87579f81
commit
98a95da9a0
1 changed files with 14 additions and 0 deletions
|
@ -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),
|
||||
]
|
||||
|
|
Loading…
Reference in a new issue