0004_project_main_forge.py 1008 Bytes
Newer Older
Guilhem Saurel's avatar
Guilhem Saurel committed
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
# Generated by Django 2.0.1 on 2018-01-29 17:12

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

def forges(apps, schema_editor):
    Forge = apps.get_model('rainboard', 'Forge')
    forges = [Forge.objects.get(name=forge) for forge in ['Github', 'Gitlab', 'Redmine', 'Openrobots']]

    Project = apps.get_model('rainboard', 'Project')
    for project in Project.objects.all():
        for forge in forges:
            if project.repo_set.filter(forge=forge).exists():
                project.main_forge = forge
                project.save()
                break


class Migration(migrations.Migration):

    dependencies = [
        ('rainboard', '0003_slugify_with_dots'),
    ]

    operations = [
        migrations.AddField(
            model_name='project',
            name='main_forge',
            field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='rainboard.Forge'),
        ),
        migrations.RunPython(forges),
    ]