# Generated by Django 3.2.15 on 2022-10-12 06:46

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


def create_links(apps, schema_editor):
    """Create links to the existing models."""
    Topic = apps.get_model("topics", "Topic")
    TopicMentionLink = apps.get_model("topics", "TopicMentionLink")

    for topic in Topic.objects.all():
        TopicMentionLink.objects.create(related_model=topic)


class Migration(migrations.Migration):

    dependencies = [
        ("chats", "0001_initial"),
        ("topics", "0011_auto_20220922_1955"),
    ]

    operations = [
        migrations.CreateModel(
            name="TopicMentionLink",
            fields=[
                (
                    "mentionlink_ptr",
                    models.OneToOneField(
                        auto_created=True,
                        on_delete=django.db.models.deletion.CASCADE,
                        parent_link=True,
                        primary_key=True,
                        serialize=False,
                        to="chats.mentionlink",
                    ),
                ),
                (
                    "related_model",
                    models.OneToOneField(
                        on_delete=django.db.models.deletion.CASCADE,
                        to="topics.topic",
                    ),
                ),
            ],
            bases=("chats.mentionlink",),
        ),
        migrations.RunPython(create_links, migrations.RunPython.noop),
    ]
