53 lines
1.8 KiB
Python
53 lines
1.8 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Generated by Django 1.10.1 on 2016-09-18 19:04
|
|
from __future__ import unicode_literals
|
|
|
|
from django.db import migrations
|
|
|
|
|
|
def move_custom_slides_to_topics(apps, schema_editor):
|
|
# We get the model from the versioned app registry;
|
|
# if we directly import it, it will be the wrong version.
|
|
ContentType = apps.get_model('contenttypes', 'ContentType')
|
|
CustomSlide = apps.get_model('core', 'CustomSlide')
|
|
Item = apps.get_model('agenda', 'Item')
|
|
Topic = apps.get_model('topics', 'Topic')
|
|
|
|
# Copy data.
|
|
content_type_custom_slide = ContentType.objects.get_for_model(CustomSlide)
|
|
content_type_topic = ContentType.objects.get_for_model(Topic)
|
|
for custom_slide in CustomSlide.objects.all():
|
|
# This line does not create a new Item because this migration model has
|
|
# no method 'get_agenda_title()'. See agenda/signals.py.
|
|
topic = Topic.objects.create(title=custom_slide.title, text=custom_slide.text)
|
|
topic.attachments.add(*custom_slide.attachments.all())
|
|
item = Item.objects.get(object_id=custom_slide.pk, content_type=content_type_custom_slide)
|
|
item.object_id = topic.pk
|
|
item.content_type = content_type_topic
|
|
item.save(skip_autoupdate=True)
|
|
|
|
# Delete old data.
|
|
CustomSlide.objects.all().delete()
|
|
content_type_custom_slide.delete()
|
|
|
|
|
|
class Migration(migrations.Migration):
|
|
|
|
dependencies = [
|
|
('core', '0004_projector_resolution'),
|
|
('topics', '0001_initial'),
|
|
]
|
|
|
|
operations = [
|
|
migrations.RunPython(
|
|
move_custom_slides_to_topics
|
|
),
|
|
migrations.RemoveField(
|
|
model_name='customslide',
|
|
name='attachments',
|
|
),
|
|
migrations.DeleteModel(
|
|
name='CustomSlide',
|
|
),
|
|
]
|