gestioCOF/cof/migrations/0009_generic_profiles.py
Ubuntu f39d1545f0 Generic profiles and migrations.
Creating profiles for BDS, COF and K-Fêt.
2017-02-10 22:12:03 +01:00

84 lines
2.2 KiB
Python

# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
def create_profile(apps, schema_editor):
CofProfile = apps.get_model("cof", "CofProfile")
Profile = apps.get_model("gestion", "Profile")
for p in CofProfile.objects.all():
profile = Profile.objects.create(
id=p.id,
user=p.user,
login_clipper=p.login_clipper,
phone=p.phone,
occupation=p.occupation,
departement=p.departement,
comments=p.comments
)
p.profile = profile
p.save()
def remove_profile(apps, schema_editor):
raise NotImplementedError
class Migration(migrations.Migration):
dependencies = [
('gestion', '0001_initial'),
('cof', '0008_py3'),
]
operations = [
migrations.RenameField(
model_name='cofprofile',
old_name='mailing_cof',
new_name='mailing',
),
migrations.AddField(
model_name='cofprofile',
name='profile',
field=models.OneToOneField(
to='gestion.Profile',
null=True,
related_name='cof'
),
preserve_default=False,
),
migrations.RunPython(create_profile, remove_profile),
migrations.RemoveField(
model_name='cofprofile',
name='comments',
),
migrations.RemoveField(
model_name='cofprofile',
name='departement',
),
migrations.RemoveField(
model_name='cofprofile',
name='login_clipper',
),
migrations.RemoveField(
model_name='cofprofile',
name='occupation',
),
migrations.RemoveField(
model_name='cofprofile',
name='phone',
),
migrations.AlterField(
model_name='cofprofile',
name='profile',
field=models.OneToOneField(
to='gestion.Profile',
related_name='cof'
),
),
migrations.RemoveField(
model_name='cofprofile',
name='user',
),
]