Completed
Push — master ( 5745d9...009919 )
by Andrew
27s
created

forwards()   A

Complexity

Conditions 2

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
c 1
b 0
f 0
dl 0
loc 7
rs 9.4285
1
# -*- coding: utf-8 -*-
2
# Generated by Django 1.9.12 on 2017-07-01 13:37
3
from __future__ import unicode_literals
4
5
import chat.models
6
from django.db import migrations, models
7
import django.db.models.deletion
8
from django.db.models import Q
9
10
def forwards(apps, schema_editor):
11
    ch_m = apps.all_models['chat']
12
    messages = ch_m['message'].objects.filter(img__isnull=False).exclude(img__exact='')
13
    for message in messages:
14
        message.content = '\u3501'
15
        chat.models.Image.objects.create(symbol='\u3501', img=message.img, message_id=message.id)
16
        message.save()
17
18
class Migration(migrations.Migration):
19
20
    dependencies =  ('chat', '0001_initial'),
21
22
    operations = [
23
        migrations.CreateModel(
24
            name='Image',
25
            fields=[
26
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
27
                ('symbol', models.CharField(max_length=1)),
28
                ('img', models.FileField(null=True, upload_to=chat.models.get_random_path)),
29
            ],
30
        ),
31
        migrations.AddField(
32
            model_name='image',
33
            name='message',
34
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='message', to='chat.Message'),
35
        ),
36
        migrations.RunPython(forwards, hints={'target_db': 'default'}),
37
38
        # migrations.RemoveField(
39
        #     model_name='message',
40
        #     name='img',
41
        # ),
42
    ]
43