# Generated by Django 4.2.1 on 2023-10-16 13:41

from django.db import migrations

def transfer_values(apps, schema_editor):
    ReceipeString = apps.get_model("receipe", "ReceipeString")
    ArticleMaps = apps.get_model("receipe", "ArticleMaps")

    #Get all unique receipeStrings form ArticleMaps
    receipeStrings = ArticleMaps.objects.values('receipeString').distinct()

    #Add all unique receipeStrings to ReceipeString
    for element in receipeStrings:
        receipeString = ReceipeString(receipeString=element['receipeString'])
        receipeString.save()

    #For each receiepString in ArticleMaps, get the corresponding ReceipeString object and add it to ArticleMaps-receipeStringRef
    for element in ArticleMaps.objects.all():
        receipeString = ReceipeString.objects.get(receipeString=element.receipeString)
        element.receipeStringRef = receipeString
        element.save()

class Migration(migrations.Migration):
    dependencies = [
        ("receipe", "0058_articlemaps_receipestringref"),
    ]

    operations = [
        migrations.RunPython(transfer_values),
    ]
