##// END OF EJS Templates
Add default tag instead of raising an error when no section is specified
Add default tag instead of raising an error when no section is specified

File last commit:

r1590:0eb7ac3c default
r1655:3877b64d default
Show More
0047_attachment_alias.py
42 lines | 1.3 KiB | text/x-python | PythonLexer
/ boards / migrations / 0047_attachment_alias.py
# -*- coding: utf-8 -*-
# Generated by Django 1.9.5 on 2016-05-21 07:43
from __future__ import unicode_literals
from boards.signals import generate_thumb
from boards.utils import get_extension
from django.db import migrations, models
class Migration(migrations.Migration):
def images_to_attachments(apps, schema_editor):
PostImage = apps.get_model('boards', 'PostImage')
Attachment = apps.get_model('boards', 'Attachment')
count = 0
images = PostImage.objects.all()
for image in images:
file_type = get_extension(image.image.name)
attachment = Attachment.objects.create(
file=image.image.file, mimetype=file_type, hash=image.hash,
alias=image.alias)
generate_thumb(attachment)
count += 1
print('Processed {} of {} images'.format(count, len(images)))
for post in image.post_images.all():
post.attachments.add(attachment)
image.image.close()
dependencies = [
('boards', '0046_auto_20160520_2307'),
]
operations = [
migrations.AddField(
model_name='attachment',
name='alias',
field=models.TextField(blank=True, null=True, unique=True),
),
migrations.RunPython(images_to_attachments),
]