pulseapi/creators/migrations/0010_auto_20171012_2002.py (15 lines of code) (raw):

# -*- coding: utf-8 -*- # Generated by Django 1.10.3 on 2017-10-12 20:02 from __future__ import unicode_literals from django.db import migrations def create_creators_for_profiles(apps, schema_editor): """ Create corresponding creator objects for each existing profile """ Creator = apps.get_model('creators', 'Creator') UserProfile = apps.get_model('profiles', 'UserProfile') profiles_without_creators = UserProfile.objects.filter(related_creator__isnull=True) for profile in profiles_without_creators: Creator.objects.create(profile=profile) class Migration(migrations.Migration): dependencies = [ ('creators', '0009_auto_20171004_1736'), ] operations = [ migrations.RunPython(create_creators_for_profiles) ]