# Generated by Django 5.2.1 on 2025-06-05 21:16

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


class Migration(migrations.Migration):

    initial = True

    dependencies = [
        ("accounts", "0002_interesttag_customuser_interests"),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name="Group",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "name",
                    models.CharField(
                        max_length=100, unique=True, verbose_name="小组名称"
                    ),
                ),
                ("description", models.TextField(blank=True, verbose_name="小组描述")),
                (
                    "cover_image",
                    models.ImageField(
                        blank=True,
                        null=True,
                        upload_to="group_covers/",
                        verbose_name="小组封面",
                    ),
                ),
                (
                    "created_at",
                    models.DateTimeField(auto_now_add=True, verbose_name="创建时间"),
                ),
                (
                    "updated_at",
                    models.DateTimeField(auto_now=True, verbose_name="更新时间"),
                ),
                (
                    "creator",
                    models.ForeignKey(
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="created_groups",
                        to=settings.AUTH_USER_MODEL,
                        verbose_name="创建者",
                    ),
                ),
                (
                    "tags",
                    models.ManyToManyField(
                        blank=True,
                        related_name="groups_with_tag",
                        to="accounts.interesttag",
                        verbose_name="相关兴趣标签",
                    ),
                ),
            ],
            options={
                "verbose_name": "小组",
                "verbose_name_plural": "小组们",
                "ordering": ["-created_at"],
            },
        ),
        migrations.CreateModel(
            name="Membership",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "date_joined",
                    models.DateTimeField(auto_now_add=True, verbose_name="加入日期"),
                ),
                (
                    "group",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        to="groups.group",
                        verbose_name="小组",
                    ),
                ),
                (
                    "user",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        to=settings.AUTH_USER_MODEL,
                        verbose_name="用户",
                    ),
                ),
            ],
            options={
                "verbose_name": "小组成员关系",
                "verbose_name_plural": "小组成员关系们",
                "ordering": ["-date_joined"],
                "unique_together": {("user", "group")},
            },
        ),
        migrations.AddField(
            model_name="group",
            name="members",
            field=models.ManyToManyField(
                blank=True,
                related_name="joined_groups",
                through="groups.Membership",
                through_fields=("group", "user"),
                to=settings.AUTH_USER_MODEL,
                verbose_name="小组成员",
            ),
        ),
    ]
