| 1 | # -*- coding: utf-8 -*-
|
|---|
| 2 | from __future__ import unicode_literals
|
|---|
| 3 |
|
|---|
| 4 | from django.db import models, migrations
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 | def fetch_main_person(apps, schema_editor):
|
|---|
| 8 | MainPerson = apps.get_model('bugapp', 'MainPerson')
|
|---|
| 9 | person_or_none = MainPerson.objects.first()
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 | class Migration(migrations.Migration):
|
|---|
| 13 |
|
|---|
| 14 | dependencies = [
|
|---|
| 15 | ]
|
|---|
| 16 |
|
|---|
| 17 | operations = [
|
|---|
| 18 | migrations.CreateModel(
|
|---|
| 19 | name='Person',
|
|---|
| 20 | fields=[
|
|---|
| 21 | ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
|
|---|
| 22 | ('name', models.IntegerField(default=None, null=True)),
|
|---|
| 23 | ],
|
|---|
| 24 | bases=(models.Model,),
|
|---|
| 25 | ),
|
|---|
| 26 |
|
|---|
| 27 | migrations.CreateModel(
|
|---|
| 28 | name='MainPerson',
|
|---|
| 29 | fields=[
|
|---|
| 30 | ('person_ptr', models.OneToOneField(parent_link=True, auto_created=True, primary_key=True, serialize=False, to='bugapp.Person')),
|
|---|
| 31 | ],
|
|---|
| 32 | bases=('bugapp.person',),
|
|---|
| 33 | ),
|
|---|
| 34 |
|
|---|
| 35 | migrations.CreateModel(
|
|---|
| 36 | name='PersonPreferences',
|
|---|
| 37 | fields=[
|
|---|
| 38 | ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
|
|---|
| 39 | ('person', models.OneToOneField(related_name='preferences', to='bugapp.Person')),
|
|---|
| 40 | ],
|
|---|
| 41 | bases=(models.Model,),
|
|---|
| 42 | ),
|
|---|
| 43 |
|
|---|
| 44 | migrations.RemoveField(
|
|---|
| 45 | model_name='person',
|
|---|
| 46 | name='name',
|
|---|
| 47 | ),
|
|---|
| 48 |
|
|---|
| 49 | migrations.RunPython(fetch_main_person, lambda apps, schema_editor: None),
|
|---|
| 50 | ]
|
|---|