0009_rename_categories.py 1.06 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from django.db import migrations


def forwards_func(apps, schema_editor):
    category = apps.get_model("pushnotifications", "Category")
    db_alias = schema_editor.connection.alias

    for key in ['general', 'pizza', 'event', 'newsletter',
                'sponsor', 'photo', 'board']:
        cat = category.objects.using(db_alias).get(key=key)
        cat.name_en = cat.name_en.title()
        cat.name_nl = cat.name_nl.title()
        cat.save()


def reverse_func(apps, schema_editor):
    category = apps.get_model("pushnotifications", "Category")
    db_alias = schema_editor.connection.alias

    for key in ['general', 'pizza', 'event', 'newsletter',
                'sponsor', 'photo', 'board']:
        cat = category.objects.using(db_alias).get(key=key)
        cat.name_en = cat.name_en.lower()
        cat.name_nl = cat.name_nl.lower()
        cat.save()


class Migration(migrations.Migration):

    dependencies = [
        ('pushnotifications', '0008_scheduledmessage'),
    ]

    operations = [
        migrations.RunPython(forwards_func, reverse_func),
    ]