Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions accounts/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Generated by Django 6.0.7 on 2026-07-29 12:25

import django.contrib.auth.models
import django.contrib.auth.validators
import django.contrib.postgres.fields
import django.utils.timezone
from django.db import migrations, models


class Migration(migrations.Migration):

initial = True

dependencies = [
('auth', '0012_alter_user_first_name_max_length'),
]

operations = [
migrations.CreateModel(
name='User',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('password', models.CharField(max_length=128, verbose_name='password')),
('last_login', models.DateTimeField(blank=True, null=True, verbose_name='last login')),
('is_superuser', models.BooleanField(default=False, help_text='Designates that this user has all permissions without explicitly assigning them.', verbose_name='superuser status')),
('username', models.CharField(error_messages={'unique': 'A user with that username already exists.'}, help_text='Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.', max_length=150, unique=True, validators=[django.contrib.auth.validators.UnicodeUsernameValidator()], verbose_name='username')),
('first_name', models.CharField(blank=True, max_length=150, verbose_name='first name')),
('last_name', models.CharField(blank=True, max_length=150, verbose_name='last name')),
('email', models.EmailField(blank=True, max_length=254, verbose_name='email address')),
('is_staff', models.BooleanField(default=False, help_text='Designates whether the user can log into this admin site.', verbose_name='staff status')),
('is_active', models.BooleanField(default=True, help_text='Designates whether this user should be treated as active. Unselect this instead of deleting accounts.', verbose_name='active')),
('date_joined', models.DateTimeField(default=django.utils.timezone.now, verbose_name='date joined')),
('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now=True)),
('name', models.CharField(max_length=50)),
('birth_date', models.DateField(blank=True, null=True)),
('gender', models.CharField(blank=True, choices=[('FEMALE', '여성'), ('MALE', '남성'), ('OTHER', '기타')], max_length=10)),
('spending_type', models.CharField(blank=True, choices=[('EXPERIENCE', '경험·만족 중시'), ('VALUE', '가성비 중시'), ('GROWTH', '성장·자기개발 중시'), ('ASSET', '자산 형성 중심')], max_length=20)),
('value_criteria', django.contrib.postgres.fields.ArrayField(base_field=models.CharField(choices=[('PRICE', '가격'), ('SATISFACTION', '만족도'), ('QUALITY', '품질'), ('UTILIZATION', '활용도'), ('LONG_TERM_VALUE', '장기 가치')], max_length=30), blank=True, default=list)),
('monthly_budget', models.CharField(blank=True, choices=[('UNDER_100K', '10만원 이하'), ('100K_300K', '10~30만원'), ('300K_500K', '30~50만원'), ('500K_1M', '50~100만원'), ('1M_2M', '100~200만원'), ('OVER_2M', '200만원 이상')], max_length=20)),
('groups', models.ManyToManyField(blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.', related_name='user_set', related_query_name='user', to='auth.group', verbose_name='groups')),
('user_permissions', models.ManyToManyField(blank=True, help_text='Specific permissions for this user.', related_name='user_set', related_query_name='user', to='auth.permission', verbose_name='user permissions')),
],
options={
'verbose_name': 'user',
'verbose_name_plural': 'users',
'abstract': False,
},
managers=[
('objects', django.contrib.auth.models.UserManager()),
],
),
]
69 changes: 68 additions & 1 deletion accounts/models.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,70 @@
from django.contrib.auth.models import AbstractUser
from django.contrib.postgres.fields import ArrayField
from django.db import models

# Create your models here.
from core.models import TimeStampedModel


class User(AbstractUser, TimeStampedModel):
class Gender(models.TextChoices):
FEMALE = "FEMALE", "여성"
MALE = "MALE", "남성"
OTHER = "OTHER", "기타"

class SpendingType(models.TextChoices):
EXPERIENCE = "EXPERIENCE", "경험·만족 중시"
VALUE = "VALUE", "가성비 중시"
GROWTH = "GROWTH", "성장·자기개발 중시"
ASSET = "ASSET", "자산 형성 중심"

class ValueCriterion(models.TextChoices):
PRICE = "PRICE", "가격"
SATISFACTION = "SATISFACTION", "만족도"
QUALITY = "QUALITY", "품질"
UTILIZATION = "UTILIZATION", "활용도"
LONG_TERM_VALUE = "LONG_TERM_VALUE", "장기 가치"

class MonthlyBudget(models.TextChoices):
UNDER_100K = "UNDER_100K", "10만원 이하"
FROM_100K_TO_300K = "100K_300K", "10~30만원"
FROM_300K_TO_500K = "300K_500K", "30~50만원"
FROM_500K_TO_1M = "500K_1M", "50~100만원"
FROM_1M_TO_2M = "1M_2M", "100~200만원"
OVER_2M = "OVER_2M", "200만원 이상"

name = models.CharField(max_length=50)

birth_date = models.DateField(
null=True,
blank=True,
)

gender = models.CharField(
max_length=10,
choices=Gender.choices,
blank=True,
)

spending_type = models.CharField(
max_length=20,
choices=SpendingType.choices,
blank=True,
)

value_criteria = ArrayField(
base_field=models.CharField(
max_length=30,
choices=ValueCriterion.choices,
),
default=list,
blank=True,
)

monthly_budget = models.CharField(
max_length=20,
choices=MonthlyBudget.choices,
blank=True,
)

def __str__(self):
return self.username
89 changes: 89 additions & 0 deletions alternatives/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# Generated by Django 6.0.7 on 2026-07-29 12:25

from django.db import migrations, models


class Migration(migrations.Migration):

initial = True

dependencies = [
]

operations = [
migrations.CreateModel(
name='Alternative',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now=True)),
('slot', models.PositiveSmallIntegerField()),
('version', models.PositiveIntegerField(default=1)),
('is_current', models.BooleanField(default=True)),
('unit_price', models.PositiveIntegerField()),
('duration', models.CharField(blank=True, max_length=100)),
('expected_effect', models.TextField(blank=True)),
('ai_reason', models.TextField(blank=True)),
('result_type', models.CharField(choices=[('QUANTITY', '수량 환산'), ('FUTURE_VALUE', '미래가치')], max_length=20)),
('equivalent_quantity', models.DecimalField(blank=True, decimal_places=2, max_digits=8, null=True)),
('future_value', models.PositiveIntegerField(blank=True, null=True)),
('display_text', models.CharField(max_length=300)),
],
options={
'ordering': ['category__display_order', 'slot', '-version'],
},
),
migrations.CreateModel(
name='AlternativeItem',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now=True)),
('name', models.CharField(max_length=200)),
('unit_label', models.CharField(blank=True, max_length=30)),
('average_price', models.PositiveIntegerField()),
('spec_note', models.CharField(blank=True, max_length=300)),
('calc_type', models.CharField(choices=[('UNIT_PRICE', '단가 환산'), ('SAVINGS', '적금'), ('DEPOSIT', '예금'), ('INVESTMENT', '투자')], default='UNIT_PRICE', max_length=20)),
('calc_params', models.JSONField(blank=True, default=dict)),
('source_name', models.CharField(max_length=200)),
('source_url', models.URLField(max_length=500)),
('effective_date', models.DateField()),
('is_active', models.BooleanField(default=True)),
],
options={
'ordering': ['category__display_order', 'name', '-effective_date'],
},
),
migrations.CreateModel(
name='Category',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now=True)),
('code', models.CharField(choices=[('TRAVEL', '여행'), ('HEALTH', '운동(건강)'), ('CULTURE', '문화(여가)'), ('LIVING', '생활편의'), ('DIGITAL', '디지털 전자기기'), ('FINANCE', '재정')], max_length=20, unique=True)),
('name', models.CharField(max_length=50)),
('emoji', models.CharField(blank=True, max_length=10)),
('display_order', models.PositiveSmallIntegerField(default=0)),
('is_active', models.BooleanField(default=True)),
],
options={
'ordering': ['display_order', 'id'],
},
),
migrations.CreateModel(
name='LLMRequestLog',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now=True)),
('purpose', models.CharField(choices=[('GENERATE', '최초 생성'), ('REGENERATE', '개별 재생성'), ('DECISION', '구매 의사결정')], max_length=20)),
('model', models.CharField(max_length=100)),
('prompt', models.TextField()),
('response', models.JSONField(blank=True, null=True)),
('status', models.CharField(choices=[('SUCCESS', '성공'), ('FAILED', '실패')], max_length=20)),
],
options={
'ordering': ['-created_at'],
},
),
]
70 changes: 70 additions & 0 deletions alternatives/migrations/0002_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Generated by Django 6.0.7 on 2026-07-29 12:25

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


class Migration(migrations.Migration):

initial = True

dependencies = [
('alternatives', '0001_initial'),
('products', '0001_initial'),
]

operations = [
migrations.AddField(
model_name='alternative',
name='consideration',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='alternatives', to='products.consideration'),
),
migrations.AddField(
model_name='alternative',
name='item',
field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='alternatives', to='alternatives.alternativeitem'),
),
migrations.AddField(
model_name='alternativeitem',
name='category',
field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='alternative_items', to='alternatives.category'),
),
migrations.AddField(
model_name='alternative',
name='category',
field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='alternatives', to='alternatives.category'),
),
migrations.AddField(
model_name='llmrequestlog',
name='consideration',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='llm_request_logs', to='products.consideration'),
),
migrations.AddIndex(
model_name='alternativeitem',
index=models.Index(fields=['category', 'is_active'], name='alt_item_category_active_idx'),
),
migrations.AddConstraint(
model_name='alternativeitem',
constraint=models.CheckConstraint(condition=models.Q(('average_price__gt', 0)), name='alternative_item_price_gt_0'),
),
migrations.AddConstraint(
model_name='alternative',
constraint=models.CheckConstraint(condition=models.Q(('slot__gte', 1), ('slot__lte', 3)), name='alternative_slot_between_1_and_3'),
),
migrations.AddConstraint(
model_name='alternative',
constraint=models.CheckConstraint(condition=models.Q(('version__gte', 1)), name='alternative_version_gte_1'),
),
migrations.AddConstraint(
model_name='alternative',
constraint=models.CheckConstraint(condition=models.Q(('unit_price__gt', 0)), name='alternative_unit_price_gt_0'),
),
migrations.AddConstraint(
model_name='alternative',
constraint=models.UniqueConstraint(fields=('consideration', 'category', 'slot', 'version'), name='unique_alternative_slot_version'),
),
migrations.AddConstraint(
model_name='alternative',
constraint=models.UniqueConstraint(condition=models.Q(('is_current', True)), fields=('consideration', 'category', 'slot'), name='unique_current_alternative_slot'),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 6.0.7 on 2026-07-29 12:27

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('alternatives', '0002_initial'),
('products', '0001_initial'),
]

operations = [
migrations.AddConstraint(
model_name='alternative',
constraint=models.CheckConstraint(condition=models.Q(models.Q(('equivalent_quantity__isnull', False), ('future_value__isnull', True), ('result_type', 'QUANTITY')), models.Q(('equivalent_quantity__isnull', True), ('future_value__isnull', False), ('result_type', 'FUTURE_VALUE')), _connector='OR'), name='valid_alternative_result'),
),
]
68 changes: 68 additions & 0 deletions alternatives/migrations/0004_seed_categories.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
from django.db import migrations


CATEGORIES = [
{
"code": "TRAVEL",
"name": "여행",
"display_order": 1,
},
{
"code": "HEALTH",
"name": "운동·건강",
"display_order": 2,
},
{
"code": "CULTURE",
"name": "문화·여가",
"display_order": 3,
},
{
"code": "LIVING",
"name": "생활·편의",
"display_order": 4,
},
{
"code": "DIGITAL",
"name": "디지털·전자기기",
"display_order": 5,
},
{
"code": "FINANCE",
"name": "재정",
"display_order": 6,
},
]


def seed_categories(apps, schema_editor):
Category = apps.get_model("alternatives", "Category")

for category in CATEGORIES:
Category.objects.update_or_create(
code=category["code"],
defaults={
"name": category["name"],
"display_order": category["display_order"],
"is_active": True,
},
)


def remove_categories(apps, schema_editor):
Category = apps.get_model("alternatives", "Category")
category_codes = [category["code"] for category in CATEGORIES]
Category.objects.filter(code__in=category_codes).delete()


class Migration(migrations.Migration):
dependencies = [
("alternatives", "0003_alternative_valid_alternative_result"),
]

operations = [
migrations.RunPython(
seed_categories,
remove_categories,
),
]
Loading