-
Notifications
You must be signed in to change notification settings - Fork 0
feat: 기록 생성 및 상세 수정 삭제 기능 구현 #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
dahliare
wants to merge
8
commits into
develop
Choose a base branch
from
feature/records
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
df9baed
feat: 기록 작성 모달 UI 구현
dahliare 480f0c7
Merge branch 'develop' into feature/records
dahliare 3f4a944
feat: 기록 생성 및 상세 수정 삭제 기능 구현(1차)
dahliare f7bb9b9
feat: 기록 필수 입력 검증 및 체크리스트 안내 구현
dahliare c18eba1
fix: 기록 대표 감정 저장 및 선택 UI 구현
dahliare 96e4657
fix: 기록 작성 및 수정페이지 필수사항 코멘트 수정
dahliare 2d036f7
fix: 기록 상세 화면에 삭제 확인 모달 구현
dahliare 2945e94
style: 기록 상세 화면 및 대표 감정 배치 개선
dahliare File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,10 @@ | ||
| from django.contrib import admin | ||
|
|
||
| from .models import Record | ||
|
|
||
|
|
||
| @admin.register(Record) | ||
| class RecordAdmin(admin.ModelAdmin): | ||
| list_display = ("id", "user", "weather", "place_name", "created_at") | ||
| list_filter = ("weather", "created_at") | ||
| search_fields = ("user__username", "content", "place_name") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,57 @@ | ||
| # 담당 C: 기록 작성, 수정 및 이미지 업로드 폼 | ||
| from django import forms | ||
|
|
||
| from .models import Record | ||
|
|
||
|
|
||
| class RecordForm(forms.ModelForm): | ||
| emotions = forms.MultipleChoiceField( | ||
| choices=[(str(number), f"감정 {number}") for number in range(1, 21)], | ||
| required=True, | ||
| error_messages={"required": "감정을 1개 이상 선택해 주세요."}, | ||
| ) | ||
| main_emotion = forms.ChoiceField( | ||
| choices=[ | ||
| ("", "메인 감정 선택"), | ||
| *[ | ||
| (str(number), f"감정 {number}") | ||
| for number in range(1, 21) | ||
| ], | ||
| ], | ||
| required=True, | ||
| error_messages={"required": "대표 감정을 선택해 주세요."}, | ||
| ) | ||
|
|
||
| class Meta: | ||
| model = Record | ||
| fields = [ | ||
| "weather", "content", "image", "emotions", "main_emotion", | ||
| "place_name", "latitude", "longitude", | ||
| ] | ||
|
|
||
| def __init__(self, *args, **kwargs): | ||
| super().__init__(*args, **kwargs) | ||
| if self.instance.pk and not self.is_bound: | ||
| self.initial["emotions"] = [ | ||
| str(emotion) for emotion in self.instance.emotions | ||
| ] | ||
| self.initial["main_emotion"] = str(self.instance.main_emotion) | ||
|
|
||
| def clean_emotions(self): | ||
| emotions = self.cleaned_data.get("emotions", []) | ||
| if len(emotions) > 3: | ||
| raise forms.ValidationError("감정은 최대 3개까지 선택할 수 있습니다.") | ||
| return [int(emotion) for emotion in emotions] | ||
|
|
||
| def clean_main_emotion(self): | ||
| return int(self.cleaned_data["main_emotion"]) | ||
|
|
||
| def clean(self): | ||
| cleaned_data = super().clean() | ||
| emotions = cleaned_data.get("emotions", []) | ||
| main_emotion = cleaned_data.get("main_emotion") | ||
| if main_emotion is not None and main_emotion not in emotions: | ||
| self.add_error( | ||
| "main_emotion", | ||
| "선택한 감정 중에서 대표 감정을 골라주세요.", | ||
| ) | ||
| return cleaned_data | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| # Generated by Django 6.0.7 on 2026-07-31 14:14 | ||
|
|
||
| import django.db.models.deletion | ||
| from django.conf import settings | ||
| from django.db import migrations, models | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
|
|
||
| initial = True | ||
|
|
||
| dependencies = [ | ||
| migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.CreateModel( | ||
| name='Record', | ||
| fields=[ | ||
| ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
| ('weather', models.CharField(choices=[('sunny', '해'), ('cloudy', '구름'), ('rainy', '비'), ('thunder', '천둥'), ('dust', '황사'), ('snowy', '눈')], max_length=10)), | ||
| ('content', models.TextField(max_length=500)), | ||
| ('image', models.ImageField(blank=True, upload_to='records/%Y/%m/%d/')), | ||
| ('emotions', models.JSONField(default=list)), | ||
| ('place_name', models.CharField(blank=True, max_length=100)), | ||
| ('latitude', models.DecimalField(blank=True, decimal_places=7, max_digits=10, null=True)), | ||
| ('longitude', models.DecimalField(blank=True, decimal_places=7, max_digits=10, null=True)), | ||
| ('created_at', models.DateTimeField(auto_now_add=True)), | ||
| ('updated_at', models.DateTimeField(auto_now=True)), | ||
| ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='heartmark_records', to=settings.AUTH_USER_MODEL)), | ||
| ], | ||
| options={ | ||
| 'ordering': ['-created_at'], | ||
| }, | ||
| ), | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| # Generated by Django 6.0.7 on 2026-08-01 13:55 | ||
|
|
||
| from django.db import migrations, models | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
|
|
||
| dependencies = [ | ||
| ('records', '0001_initial'), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.AlterField( | ||
| model_name='record', | ||
| name='image', | ||
| field=models.ImageField(upload_to='records/%Y/%m/%d/'), | ||
| ), | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| from django.core.validators import MaxValueValidator, MinValueValidator | ||
| from django.db import migrations, models | ||
|
|
||
|
|
||
| def set_existing_main_emotions(apps, schema_editor): | ||
| Record = apps.get_model("records", "Record") | ||
| for record in Record.objects.all().iterator(): | ||
| emotions = record.emotions if isinstance(record.emotions, list) else [] | ||
| if not emotions: | ||
| emotions = [1] | ||
| record.emotions = emotions | ||
| record.main_emotion = int(emotions[0]) | ||
| record.save(update_fields=["emotions", "main_emotion"]) | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
| dependencies = [ | ||
| ("records", "0002_alter_record_image"), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.AddField( | ||
| model_name="record", | ||
| name="main_emotion", | ||
| field=models.PositiveSmallIntegerField( | ||
| blank=True, | ||
| null=True, | ||
| validators=[MinValueValidator(1), MaxValueValidator(20)], | ||
| ), | ||
| ), | ||
| migrations.RunPython( | ||
| set_existing_main_emotions, | ||
| migrations.RunPython.noop, | ||
| ), | ||
| migrations.AlterField( | ||
| model_name="record", | ||
| name="main_emotion", | ||
| field=models.PositiveSmallIntegerField( | ||
| validators=[MinValueValidator(1), MaxValueValidator(20)], | ||
| ), | ||
| ), | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,75 @@ | ||
| # 담당 C: Record 생성, 상세, 수정, 삭제 | ||
| from django.conf import settings | ||
| from django.core.exceptions import ValidationError | ||
| from django.core.validators import MaxValueValidator, MinValueValidator | ||
| from django.db import models | ||
|
|
||
|
|
||
| class Record(models.Model): | ||
| class Weather(models.TextChoices): | ||
| SUNNY = "sunny", "해" | ||
| CLOUDY = "cloudy", "구름" | ||
| RAINY = "rainy", "비" | ||
| THUNDER = "thunder", "천둥" | ||
| DUST = "dust", "황사" | ||
| SNOWY = "snowy", "눈" | ||
|
|
||
| user = models.ForeignKey( | ||
| settings.AUTH_USER_MODEL, | ||
| on_delete=models.CASCADE, | ||
| related_name="heartmark_records", | ||
| ) | ||
| weather = models.CharField(max_length=10, choices=Weather.choices) | ||
| content = models.TextField(max_length=500) | ||
| image = models.ImageField(upload_to="records/%Y/%m/%d/") | ||
| emotions = models.JSONField(default=list) | ||
|
dahliare marked this conversation as resolved.
|
||
| main_emotion = models.PositiveSmallIntegerField( | ||
| validators=[MinValueValidator(1), MaxValueValidator(20)], | ||
| ) | ||
|
|
||
| # TODO: locations.Place 규격 확정 후 ForeignKey 연결을 검토합니다. | ||
| place_name = models.CharField(max_length=100, blank=True) | ||
| latitude = models.DecimalField(max_digits=10, decimal_places=7, null=True, blank=True) | ||
| longitude = models.DecimalField(max_digits=10, decimal_places=7, null=True, blank=True) | ||
|
|
||
| created_at = models.DateTimeField(auto_now_add=True) | ||
| updated_at = models.DateTimeField(auto_now=True) | ||
|
|
||
| class Meta: | ||
| ordering = ["-created_at"] | ||
|
|
||
| def __str__(self): | ||
| return f"{self.user}의 기록 ({self.created_at:%Y-%m-%d})" | ||
|
|
||
| @property | ||
| def weather_image_name(self): | ||
| return f"{self.weather}.png" | ||
|
|
||
| @property | ||
| def emotion_image_names(self): | ||
| return [f"emotion-{int(number):02d}.png" for number in self.emotions] | ||
|
|
||
| @property | ||
| def emotion_items(self): | ||
| numbers = [int(number) for number in self.emotions] | ||
| numbers.sort(key=lambda number: number != self.main_emotion) | ||
| return [ | ||
| { | ||
| "number": number, | ||
| "image_name": f"emotion-{number:02d}.png", | ||
| "is_main": number == self.main_emotion, | ||
| } | ||
| for number in numbers | ||
| ] | ||
|
|
||
| def clean(self): | ||
| super().clean() | ||
| if not isinstance(self.emotions, list): | ||
| raise ValidationError({"emotions": "감정은 목록 형태여야 합니다."}) | ||
| if not self.emotions: | ||
| raise ValidationError({"emotions": "감정을 1개 이상 선택해 주세요."}) | ||
| if len(self.emotions) > 3: | ||
| raise ValidationError({"emotions": "감정은 최대 3개까지 선택할 수 있습니다."}) | ||
| if self.main_emotion not in self.emotions: | ||
| raise ValidationError({ | ||
| "main_emotion": "선택한 감정 중에서 대표 감정을 골라주세요." | ||
| }) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.