# Generated by Django 5.2.8 on 2025-12-07 16:33

from django.db import migrations, models


WIKI_URL = "https://en.wikipedia.org/wiki/Application_software"


def set_app_wiki_url(apps, schema_editor):
    Application = apps.get_model("app", "Application")
    ApplicationModel = apps.get_model("app", "ApplicationModel")

    try:
        application = Application.objects.get(name="app")
    except Application.DoesNotExist:
        return

    ApplicationModel.objects.filter(
        application=application, label__iexact="app.Application"
    ).update(wiki_url=WIKI_URL)


def unset_app_wiki_url(apps, schema_editor):
    Application = apps.get_model("app", "Application")
    ApplicationModel = apps.get_model("app", "ApplicationModel")

    try:
        application = Application.objects.get(name="app")
    except Application.DoesNotExist:
        return

    ApplicationModel.objects.filter(
        application=application, label__iexact="app.Application", wiki_url=WIKI_URL
    ).update(wiki_url="")


class Migration(migrations.Migration):

    dependencies = [
        ("app", "0002_applicationmodel"),
    ]

    operations = [
        migrations.AddField(
            model_name="applicationmodel",
            name="wiki_url",
            field=models.URLField(blank=True),
        ),
        migrations.RunPython(set_app_wiki_url, reverse_code=unset_app_wiki_url),
    ]
