From 608e67fe6ac96d9254280ba7421ef98bc3696fd0 Mon Sep 17 00:00:00 2001 From: Ludovic Stephan Date: Fri, 24 Mar 2017 21:23:04 -0300 Subject: [PATCH] Add RunPython script to migration --- kfet/migrations/0049_auto_20170325_0110.py | 34 ++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 kfet/migrations/0049_auto_20170325_0110.py diff --git a/kfet/migrations/0049_auto_20170325_0110.py b/kfet/migrations/0049_auto_20170325_0110.py new file mode 100644 index 00000000..0620dd7a --- /dev/null +++ b/kfet/migrations/0049_auto_20170325_0110.py @@ -0,0 +1,34 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + + +def adapt_operation_types(apps, schema_editor): + Operation = apps.get_model("kfet", "Operation") + + for ope in Operation.objects.all(): + if (not ope.is_checkout and + ope.type in ['deposit', 'withdraw']): + ope.type = 'edit' + ope.save() + + +class Migration(migrations.Migration): + + dependencies = [ + ('kfet', '0048_article_hidden'), + ] + + operations = [ + migrations.AlterField( + model_name='operation', + name='type', + field=models.CharField(choices=[('purchase', 'Achat'), ('deposit', 'Charge'), ('withdraw', 'Retrait'), ('initial', 'Initial'), ('edit', 'Édition')], max_length=8), + ), + migrations.RunPython(adapt_operation_types), + migrations.RemoveField( + model_name='operation', + name='is_checkout', + ), + ]