Add temporary ext_id_old for Corporation and CorpContact

This commit is contained in:
Claude Paroz 2017-07-18 17:43:29 +02:00
parent 283bd36d02
commit 3ae3820fc3
2 changed files with 33 additions and 0 deletions

View file

@ -0,0 +1,31 @@
from django.db import migrations, models
def migrate_extid(apps, schema_editor):
Corporation = apps.get_model("stages", "Corporation")
CorpContact = apps.get_model("stages", "CorpContact")
Corporation.objects.update(ext_id_old=models.F('ext_id'))
CorpContact.objects.update(ext_id_old=models.F('ext_id'))
Corporation.objects.update(ext_id=None)
CorpContact.objects.update(ext_id=None)
class Migration(migrations.Migration):
dependencies = [
('stages', '0018_removed_referent_model'),
]
operations = [
migrations.AddField(
model_name='corpcontact',
name='ext_id_old',
field=models.IntegerField(blank=True, null=True, verbose_name='ID externe (ancien)'),
),
migrations.AddField(
model_name='corporation',
name='ext_id_old',
field=models.IntegerField(blank=True, null=True, verbose_name='ID externe (ancien)'),
),
migrations.RunPython(migrate_extid, migrations.RunPython.noop),
]

View file

@ -196,6 +196,7 @@ class Student(models.Model):
class Corporation(models.Model):
ext_id = models.IntegerField(null=True, blank=True, verbose_name='ID externe')
ext_id_old = models.IntegerField(null=True, blank=True, verbose_name='ID externe (ancien)')
name = models.CharField(max_length=100, verbose_name='Nom', unique=True)
short_name = models.CharField(max_length=40, blank=True, verbose_name='Nom court')
district = models.CharField(max_length=20, blank=True, verbose_name='Canton')
@ -223,6 +224,7 @@ class Corporation(models.Model):
class CorpContact(models.Model):
corporation = models.ForeignKey(Corporation, verbose_name='Institution', on_delete=models.CASCADE)
ext_id = models.IntegerField(null=True, blank=True, verbose_name='ID externe')
ext_id_old = models.IntegerField(null=True, blank=True, verbose_name='ID externe (ancien)')
is_main = models.BooleanField(default=False, verbose_name='Contact principal')
always_cc = models.BooleanField(default=False, verbose_name='Toujours en copie')
title = models.CharField(max_length=40, blank=True, verbose_name='Civilité')