8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-20 10:23:12 +00:00
re2o/topologie/migrations/0071_auto_20190218_1936.py

63 lines
2.1 KiB
Python
Raw Normal View History

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):
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():
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(
model_name="room", name="name", field=models.CharField(max_length=255)
2019-02-18 20:11:51 +00:00
),
migrations.AddField(
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(
name="room", unique_together=set([("name", "building")])
2019-02-18 20:11:51 +00:00
),
migrations.AlterField(
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(
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
]