# -*- 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), ]