123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- # -*- coding: utf-8 -*-
- # Generated by Django 1.11.2 on 2017-06-14 20:42
- from __future__ import unicode_literals
- from django.db import migrations, models
- import django.db.models.deletion
- def migrate_adhesions(apps, schema_editor):
- User = apps.get_model("adhesions", "User")
- Corporation = apps.get_model("adhesions", "Corporation")
- Adhesion = apps.get_model("adhesions", "Adhesion")
- ContentType = apps.get_model("contenttypes", "ContentType")
- user_type = ContentType.objects.get_for_model(User)
- corp_type = ContentType.objects.get_for_model(Corporation)
- db_alias = schema_editor.connection.alias
- for adh in Adhesion.objects.using(db_alias).all():
- if adh.adherent_type == user_type:
- adh.user = User.objects.using(db_alias).get(pk=adh.adherent_id)
- else:
- assert(adh.adherent_type == corp_type)
- adh.corporation = Corporation.objects.using(db_alias).get(pk=adh.adherent_id)
- adh.save()
- class Migration(migrations.Migration):
- dependencies = [
- ('adhesions', '0013_adhesion_active'),
- ('accounts', '0006_auto_20170607_2306'),
- ]
- operations = [
- migrations.AddField(
- model_name='adhesion',
- name='user',
- field=models.OneToOneField(null=True, on_delete=django.db.models.deletion.CASCADE, to='adhesions.User'),
- ),
- migrations.AddField(
- model_name='adhesion',
- name='corporation',
- field=models.OneToOneField(null=True, on_delete=django.db.models.deletion.CASCADE, to='adhesions.Corporation'),
- ),
- migrations.RunPython(migrate_adhesions),
- ]
|