# Generated by Django 2.1.2 on 2020-03-15 03:49

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

def switch_to_post(apps, schema_editor):
    OldBattery = apps.get_model('login', 'OldBattery')
    NewBattery = apps.get_model('login', 'NewBattery')
    for un in OldBattery.objects.all():
        un.delete()

def switch_to_nopost(apps, schema_editor):
    OldBattery = apps.get_model('login', 'OldBattery')
    NewBattery = apps.get_model('login', 'NewBattery')

    for un in NewBattery.objects.all():
        un.delete()

class Migration(migrations.Migration):

    dependencies = [
        ('login', '0008_auto_20200315_1242'),
    ]

    operations = [
        migrations.RenameModel('Battery', 'OldBattery'),
        migrations.CreateModel(
            name="NewBattery",
            fields=[
                ('rentalitem_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True,serialize=False, to='login.RentalItem')),
                ('borrowed_by', models.OneToOneField('login.Student',related_name='ba', null=True, blank=True, on_delete=models.DO_NOTHING)),
                ('return_time', models.DateTimeField(auto_now_add=True)),                
            ],
            bases=('login.RentalItem',),
        ),
        migrations.RunPython(switch_to_post, switch_to_nopost),
        migrations.DeleteModel('OldBattery'),
        migrations.RenameModel('NewBattery', 'Battery')
    ]
