0066_auto_20171025_1148.py
54 lines
| 1.9 KiB
| text/x-python
|
PythonLexer
neko259
|
r1951 | # -*- coding: utf-8 -*- | ||
# Generated by Django 1.11 on 2017-10-25 08:48 | ||||
from __future__ import unicode_literals | ||||
from django.db import migrations, models | ||||
import django.db.models.deletion | ||||
class Migration(migrations.Migration): | ||||
dependencies = [ | ||||
('boards', '0065_attachmentsticker'), | ||||
] | ||||
def stickers_to_pack(apps, schema_editor): | ||||
AttachmentSticker = apps.get_model('boards', 'AttachmentSticker') | ||||
StickerPack = apps.get_model('boards', 'StickerPack') | ||||
stickers = AttachmentSticker.objects.all() | ||||
if len(stickers) > 0: | ||||
stickerpack = StickerPack.objects.create(name='general') | ||||
for sticker in stickers: | ||||
sticker.stickerpack = stickerpack | ||||
if '/' in sticker.name: | ||||
sticker.name = sticker.name.split('/')[1] | ||||
sticker.save() | ||||
operations = [ | ||||
migrations.CreateModel( | ||||
name='StickerPack', | ||||
fields=[ | ||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||||
('name', models.TextField(unique=True)), | ||||
('tripcode', models.TextField(blank=True)), | ||||
], | ||||
), | ||||
migrations.AddField( | ||||
model_name='attachmentsticker', | ||||
name='stickerpack', | ||||
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='boards.StickerPack', null=True), | ||||
preserve_default=False, | ||||
), | ||||
migrations.AddField( | ||||
model_name='thread', | ||||
name='stickerpack', | ||||
field=models.BooleanField(default=False), | ||||
), | ||||
migrations.RunPython(stickers_to_pack), | ||||
migrations.AlterField( | ||||
model_name='attachmentsticker', | ||||
name='stickerpack', | ||||
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='boards.StickerPack', null=False), | ||||
), | ||||
] | ||||