<gh_stars>1-10
# -*- coding: utf-8 -*-
# Generated by Django 1.10.5 on 2017-02-14 16:27


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


def forward(apps, schema_editor):
    # Explicitly set a few plans to have mail and keys --JLS
    # This only applies to Office Nomads but won't cause problems to other data.
    User = apps.get_model(settings.AUTH_USER_MODEL)
    MembershipPlan = apps.get_model("nadine", "MembershipPlan")
    # Resident gets mail and key
    resident_plan = MembershipPlan.objects.filter(name="Resident").first()
    if resident_plan:
        resident_plan.has_key = True
        resident_plan.has_mail = True
        resident_plan.save()
    # ON Team gets a key
    on_team_plan = MembershipPlan.objects.filter(name="ON Team").first()
    if on_team_plan:
        on_team_plan.has_key = True
        on_team_plan.save()


def reverse(apps, schema_editor):
    pass


class Migration(migrations.Migration):

    dependencies = [
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
        ('nadine', '0026_bill_in_progress'),
    ]

    operations = [
        # Rename the old Membership model
        migrations.RenameModel(
            old_name='Membership',
            new_name='OldMembership',
        ),
        migrations.AlterModelOptions(
            name='oldmembership',
            options={'ordering': ['start_date'], 'verbose_name': 'OldMembership', 'verbose_name_plural': 'OldMemberships'},
        ),
        migrations.AlterField(
            model_name='oldmembership',
            name='user',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='+', to=settings.AUTH_USER_MODEL),
        ),
        migrations.AlterField(
            model_name='bill',
            name='membership',
            field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='nadine.OldMembership'),
        ),
        migrations.AddField(
            model_name='membershipplan',
            name='has_key',
            field=models.NullBooleanField(default=False),
        ),
        migrations.AddField(
            model_name='membershipplan',
            name='has_mail',
            field=models.NullBooleanField(default=False),
        ),

        # Rename old Bill model
        migrations.RenameModel(
            old_name='Bill',
            new_name='OldBill',
        ),
        migrations.AlterField(
            model_name='oldbill',
            name='user',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='old_bill', to=settings.AUTH_USER_MODEL),
        ),

        migrations.RunPython(forward, reverse),
    ]
