ojuso-map/apps/map/migrations/0066_copy_images_to_imagefiles.py

33 lines
933 B
Python
Raw Normal View History

# -*- coding: utf-8 -*-
# Generated by Django 1.11.6 on 2018-05-26 15:48
from __future__ import unicode_literals
from django.db import migrations
def copy_images(apps, schema_editor):
2019-08-19 21:37:32 +00:00
CaseStudy = apps.get_model("map", "CaseStudy")
ImageFile = apps.get_model("files", "ImageFile")
User = apps.get_model("auth", "User")
for case_study in CaseStudy.objects.all():
author = case_study.author
if author is None:
2019-08-19 21:37:32 +00:00
author = User.objects.get(username="root")
imagefile = ImageFile(
file=case_study.image,
caption=case_study.image_caption,
credit=case_study.image_credit,
2019-08-19 21:37:32 +00:00
user=author,
)
imagefile.save()
case_study.images.add(imagefile)
class Migration(migrations.Migration):
2019-08-19 21:37:32 +00:00
dependencies = [("map", "0065_casestudy_images")]
2019-08-19 21:37:32 +00:00
operations = [migrations.RunPython(copy_images, migrations.RunPython.noop)]