# -*- coding: utf-8 -*-
# Generated by Django 1.9.12 on 2017-07-01 13:37
from __future__ import unicode_literals

import chat.models
from django.db import migrations, models
import django.db.models.deletion
from django.db.models import Q

def forwards(apps, schema_editor):
    ch_m = apps.all_models['chat']
    messages = ch_m['message'].objects.filter(img__isnull=False).exclude(img__exact='')
    for message in messages:
        message.content = '\u3501'
        chat.models.Image.objects.create(symbol='\u3501', img=message.img, message_id=message.id)
        message.save()

class Migration(migrations.Migration):

    dependencies =  ('chat', '0001_initial'),

    operations = [
        migrations.CreateModel(
            name='Image',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('symbol', models.CharField(max_length=1)),
                ('img', models.FileField(null=True, upload_to=chat.models.get_random_path)),
            ],
        ),
        migrations.AddField(
            model_name='image',
            name='message',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='message', to='chat.Message'),
        ),
        migrations.RunPython(forwards, hints={'target_db': 'default'}),

        # migrations.RemoveField(
        #     model_name='message',
        #     name='img',
        # ),
    ]
