Skip to content

Commit 6debe96

Browse files
committed
fix: soft-delete된 객체는 노출되지 않도록 수정
1 parent 66ad90c commit 6debe96

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

app/event/presentation/models.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from __future__ import annotations
22

3+
from contextlib import suppress
4+
35
from core.models import BaseAbstractModel, BaseAbstractModelQuerySet, MarkdownField
46
from django.contrib.auth import get_user_model
57
from django.db import models
@@ -87,6 +89,16 @@ class Presentation(BaseAbstractModel):
8789
def __str__(self) -> str:
8890
return f"[{self.type.name}] {self.title}"
8991

92+
def active_categories(self) -> list[PresentationCategory]:
93+
with suppress(AttributeError):
94+
return self._prefetched_active_categories
95+
return list(self.categories.filter_active())
96+
97+
def active_speakers(self) -> list[PresentationSpeaker]:
98+
with suppress(AttributeError):
99+
return self._prefetched_active_speakers
100+
return list(self.speakers.filter_active())
101+
90102

91103
class PresentationCategoryRelation(models.Model):
92104
presentation = models.ForeignKey(Presentation, on_delete=models.CASCADE)

app/event/presentation/serializers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ class Meta:
4343

4444
class PresentationSerializer(serializers.ModelSerializer):
4545
image = serializers.FileField(source="image.file", read_only=True, allow_null=True)
46-
categories = PresentationCategorySerializer(many=True, read_only=True)
47-
speakers = PresentationSpeakerSerializer(many=True, read_only=True)
46+
categories = PresentationCategorySerializer(many=True, read_only=True, source="active_categories")
47+
speakers = PresentationSpeakerSerializer(many=True, read_only=True, source="active_speakers")
4848
room_schedules = RoomScheduleSerializer(source="room_schedules_set", many=True, read_only=True)
4949
call_for_presentation_schedules = CallForPresentationScheduleSerializer(many=True, read_only=True)
5050

0 commit comments

Comments
 (0)