0010_auto_20170912_2028.py 1.76 KB
Newer Older
Sli's avatar
Sli committed
1
2
3
4
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import migrations, models
5

Sli's avatar
Sli committed
6
from club.models import Club
7
from core.operations import PsqlRunOnly
8
import django.db.models.deletion
Sli's avatar
Sli committed
9
10
11


def generate_club_pages(apps, schema_editor):
Sli's avatar
Sli committed
12
    def recursive_generate_club_page(club):
Sli's avatar
Sli committed
13
        club.make_page()
Sli's avatar
Sli committed
14
15
        for child in Club.objects.filter(parent=club).all():
            recursive_generate_club_page(child)
Sli's avatar
Sli committed
16

Sli's avatar
Sli committed
17
18
    for club in Club.objects.filter(parent=None).all():
        recursive_generate_club_page(club)
Sli's avatar
Sli committed
19
20
21
22


class Migration(migrations.Migration):

Sli's avatar
Sli committed
23
    dependencies = [("core", "0024_auto_20170906_1317"), ("club", "0010_club_logo")]
Sli's avatar
Sli committed
24
25
26

    operations = [
        migrations.AddField(
Sli's avatar
Sli committed
27
28
29
            model_name="club",
            name="is_active",
            field=models.BooleanField(default=True, verbose_name="is active"),
Sli's avatar
Sli committed
30
31
        ),
        migrations.AddField(
Sli's avatar
Sli committed
32
33
34
            model_name="club",
            name="page",
            field=models.OneToOneField(
35
36
37
38
39
                on_delete=django.db.models.deletion.CASCADE,
                related_name="club",
                blank=True,
                null=True,
                to="core.Page",
Sli's avatar
Sli committed
40
            ),
Sli's avatar
Sli committed
41
        ),
42
        migrations.AddField(
Sli's avatar
Sli committed
43
44
45
46
47
48
49
50
51
52
53
54
            model_name="club",
            name="short_description",
            field=models.CharField(
                verbose_name="short description",
                max_length=1000,
                default="",
                blank=True,
                null=True,
            ),
        ),
        PsqlRunOnly(
            "SET CONSTRAINTS ALL IMMEDIATE", reverse_sql=migrations.RunSQL.noop
55
        ),
Sli's avatar
Sli committed
56
        migrations.RunPython(generate_club_pages),
Sli's avatar
Sli committed
57
58
59
        PsqlRunOnly(
            migrations.RunSQL.noop, reverse_sql="SET CONSTRAINTS ALL IMMEDIATE"
        ),
Sli's avatar
Sli committed
60
    ]