Gitlab CSE Unil

0004_auto_20150424_1209.py 630 Bytes
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
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations


def init_owners(apps, schema_editor):
    """
    Initialize new `owners` field by adding the current `owner` to it
    :param apps:
    :param schema_editor:
    :return:
    """
    AnObj = apps.get_model("adim", "AnObj")
    for anobj in AnObj.objects.all():
        if len(anobj.owners.all()) == 0:
            anobj.owners.add(anobj.owner)


class Migration(migrations.Migration):

    dependencies = [
        ('adim', '0003_anobj_owners'),
    ]

    operations = [
        migrations.RunPython(init_owners),
    ]