2019-02-18 20:11:51 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# Generated by Django 1.10.7 on 2019-02-18 18:36
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
|
|
|
from django.db import migrations, models
|
|
|
|
import django.db.models.deletion
|
|
|
|
|
|
|
|
|
|
|
|
class Migration(migrations.Migration):
|
|
|
|
|
2019-11-04 16:55:03 +00:00
|
|
|
dependencies = [("topologie", "0070_auto_20190218_1743")]
|
2019-02-18 20:11:51 +00:00
|
|
|
|
|
|
|
def transfer_room(apps, schema_editor):
|
|
|
|
db_alias = schema_editor.connection.alias
|
|
|
|
room_obj = apps.get_model("topologie", "Room")
|
|
|
|
building_obj = apps.get_model("topologie", "Building")
|
|
|
|
dorm_obj = apps.get_model("topologie", "Dormitory")
|
|
|
|
dorm = dorm_obj.objects.using(db_alias).first()
|
|
|
|
for room in room_obj.objects.using(db_alias).all():
|
2019-11-04 16:55:03 +00:00
|
|
|
building, created = building_obj.objects.using(db_alias).get_or_create(
|
|
|
|
name=room.name[0].upper(), dormitory=dorm
|
|
|
|
)
|
2019-02-18 20:11:51 +00:00
|
|
|
room.building = building
|
|
|
|
room.name = room.name[1:]
|
|
|
|
room.save()
|
|
|
|
|
|
|
|
def untransfer_room(apps, schema_editor):
|
|
|
|
pass
|
|
|
|
|
|
|
|
operations = [
|
|
|
|
migrations.AlterField(
|
2019-11-04 16:55:03 +00:00
|
|
|
model_name="room", name="name", field=models.CharField(max_length=255)
|
2019-02-18 20:11:51 +00:00
|
|
|
),
|
|
|
|
migrations.AddField(
|
2019-11-04 16:55:03 +00:00
|
|
|
model_name="room",
|
|
|
|
name="building",
|
|
|
|
field=models.ForeignKey(
|
|
|
|
blank=True,
|
|
|
|
null=True,
|
|
|
|
on_delete=django.db.models.deletion.PROTECT,
|
|
|
|
to="topologie.Building",
|
|
|
|
),
|
2019-02-18 20:11:51 +00:00
|
|
|
),
|
|
|
|
migrations.AlterUniqueTogether(
|
2019-11-04 16:55:03 +00:00
|
|
|
name="room", unique_together=set([("name", "building")])
|
2019-02-18 20:11:51 +00:00
|
|
|
),
|
|
|
|
migrations.AlterField(
|
2019-11-04 16:55:03 +00:00
|
|
|
model_name="building",
|
|
|
|
name="dormitory",
|
|
|
|
field=models.ForeignKey(
|
|
|
|
on_delete=django.db.models.deletion.PROTECT, to="topologie.Dormitory"
|
|
|
|
),
|
2019-02-18 20:11:51 +00:00
|
|
|
),
|
|
|
|
migrations.RunPython(transfer_room, untransfer_room),
|
|
|
|
migrations.AlterField(
|
2019-11-04 16:55:03 +00:00
|
|
|
model_name="room",
|
|
|
|
name="building",
|
|
|
|
field=models.ForeignKey(
|
|
|
|
on_delete=django.db.models.deletion.PROTECT, to="topologie.Building"
|
|
|
|
),
|
|
|
|
),
|
2019-02-18 20:11:51 +00:00
|
|
|
]
|