8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-12-18 04:53:47 +00:00
re2o/topologie/migrations/0071_auto_20190218_1936.py
Hugo Levy-Falk c4a104b3b6 I like my black.
Just ran black on the whoe repository. Fix #210.
2019-11-04 22:47:24 +01:00

62 lines
2.1 KiB
Python

# -*- 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")]
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
)
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)
),
migrations.AddField(
model_name="room",
name="building",
field=models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.PROTECT,
to="topologie.Building",
),
),
migrations.AlterUniqueTogether(
name="room", unique_together=set([("name", "building")])
),
migrations.AlterField(
model_name="building",
name="dormitory",
field=models.ForeignKey(
on_delete=django.db.models.deletion.PROTECT, to="topologie.Dormitory"
),
),
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"
),
),
]