39949562c1
Closes #62
37 lines
962 B
Python
37 lines
962 B
Python
# -*- 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):
|
|
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:
|
|
author = User.objects.get(username='root')
|
|
|
|
imagefile = ImageFile(
|
|
file=case_study.image,
|
|
caption=case_study.image_caption,
|
|
credit=case_study.image_credit,
|
|
user=author
|
|
)
|
|
imagefile.save()
|
|
case_study.images.add(imagefile)
|
|
|
|
|
|
class Migration(migrations.Migration):
|
|
|
|
dependencies = [
|
|
('map', '0065_casestudy_images'),
|
|
]
|
|
|
|
operations = [
|
|
migrations.RunPython(copy_images, migrations.RunPython.noop),
|
|
]
|