21
apps/map/migrations/0065_casestudy_images.py
Normal file
21
apps/map/migrations/0065_casestudy_images.py
Normal file
@ -0,0 +1,21 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.11.6 on 2018-05-26 15:47
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('files', '0003_auto_20180526_1547'),
|
||||
('map', '0064_auto_20180526_1536'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='casestudy',
|
||||
name='images',
|
||||
field=models.ManyToManyField(blank=True, related_name='image_for', to='files.ImageFile', verbose_name='Images'),
|
||||
),
|
||||
]
|
36
apps/map/migrations/0066_copy_images_to_imagefiles.py
Normal file
36
apps/map/migrations/0066_copy_images_to_imagefiles.py
Normal file
@ -0,0 +1,36 @@
|
||||
# -*- 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),
|
||||
]
|
27
apps/map/migrations/0067_remove_old_images.py
Normal file
27
apps/map/migrations/0067_remove_old_images.py
Normal file
@ -0,0 +1,27 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.11.6 on 2018-05-29 05:20
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('map', '0066_copy_images_to_imagefiles'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name='casestudy',
|
||||
name='image',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='casestudy',
|
||||
name='image_caption',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='casestudy',
|
||||
name='image_credit',
|
||||
),
|
||||
]
|
Reference in New Issue
Block a user