# Generated by Django 3.2 on 2021-05-25 18:02

import core.utils
from django.db import migrations, models
import django.db.models.deletion
import django.utils.timezone

def add_specialties_to_first_medic(apps, schema_editor):
    Medic = apps.get_model('core', 'Medic')
    Specialty = apps.get_model('core', 'Specialty')
    Specialty.objects.all().update(medic=Medic.objects.first())

class Migration(migrations.Migration):

    dependencies = [
        ('core', '0002_auto_20210518_1543'),
    ]

    operations = [
        migrations.CreateModel(
            name='Allergy',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('name', models.CharField(max_length=100, unique=True)),
                ('created_at', models.DateTimeField(default=django.utils.timezone.now, editable=False)),
                ('updated_at', core.utils.AutoDateTimeField(default=django.utils.timezone.now, editable=False)),
            ],
            options={
                'verbose_name_plural': 'allergies',
            },
        ),
        migrations.AlterModelOptions(
            name='specialty',
            options={'verbose_name_plural': 'specialties'},
        ),
        migrations.RemoveField(
            model_name='medic',
            name='specialties',
        ),
        migrations.RemoveField(
            model_name='patient',
            name='allergies',
        ),
        migrations.AddField(
            model_name='specialty',
            name='medic',
            field=models.ForeignKey(
                null=True,
                on_delete=django.db.models.deletion.CASCADE,
                related_name='specialties',
                to='core.medic'
            ),
            preserve_default=False,
        ),
        migrations.RunPython(add_specialties_to_first_medic),
        migrations.AlterField(
            model_name='specialty',
            name='medic',
            field=models.ForeignKey(
                null=False,
                on_delete=django.db.models.deletion.CASCADE,
                related_name='specialties',
                to='core.medic'
            ),
            preserve_default=False,
        ),
        migrations.DeleteModel(
            name='MedicSpecialty',
        ),
        migrations.AddField(
            model_name='allergy',
            name='patient',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='allergies', to='core.patient'),
        ),
    ]
