from decimal import Decimal from django.db import migrations def create_default_plans(apps, schema_editor): Plan = apps.get_model("club", "MembershipPlan") plans = [ { "name": "Старт 1 месяц", "description": "Базовый доступ ко всем зонам клуба.", "duration_days": 30, "price": Decimal("2490.00"), }, { "name": "Сила 3 месяца", "description": "Три месяца + гостевой визит раз в месяц.", "duration_days": 90, "price": Decimal("6490.00"), }, { "name": "Премиум 12 месяцев", "description": "Год без ограничений, приоритетная запись на тренировки.", "duration_days": 365, "price": Decimal("19900.00"), }, ] for data in plans: Plan.objects.update_or_create(name=data["name"], defaults=data) def remove_default_plans(apps, schema_editor): Plan = apps.get_model("club", "MembershipPlan") Plan.objects.filter( name__in=[ "Старт 1 месяц", "Сила 3 месяца", "Премиум 12 месяцев", ] ).delete() class Migration(migrations.Migration): dependencies = [ ("club", "0001_initial"), ] operations = [ migrations.RunPython(create_default_plans, remove_default_plans), ]