##// END OF EJS Templates
Added ability to add links to specific domains and show the domain logo as an image substitute
Added ability to add links to specific domains and show the domain logo as an image substitute

File last commit:

r1590:0eb7ac3c default
r1695:6ee0d7fe default
Show More
0047_attachment_alias.py
42 lines | 1.3 KiB | text/x-python | PythonLexer
/ boards / migrations / 0047_attachment_alias.py
neko259
Store images as regular attachments instead of separate model
r1590 # -*- 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),
]