feat: Attachment 모델 추가 및 관련 기능 구현
All checks were successful
Build And Test / build-and-push (push) Successful in 2m5s
All checks were successful
Build And Test / build-and-push (push) Successful in 2m5s
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@ -1,4 +1,6 @@
|
||||
from django.db import models
|
||||
from django.db.models.signals import pre_delete
|
||||
from django.dispatch import receiver
|
||||
from django.conf import settings
|
||||
from django.contrib.auth.models import User
|
||||
|
||||
@ -56,3 +58,31 @@ class Comment(models.Model):
|
||||
|
||||
def __str__(self):
|
||||
return f"Comment by {self.author_name} on {self.post.title}"
|
||||
|
||||
|
||||
class Attachment(models.Model):
|
||||
"""첨부파일 모델"""
|
||||
post = models.ForeignKey(
|
||||
Post,
|
||||
related_name="attachments",
|
||||
on_delete=models.CASCADE,
|
||||
null=True,
|
||||
blank=True
|
||||
) # null이면 임시 파일 (아직 게시글에 연결되지 않음)
|
||||
file = models.FileField(upload_to='attachments/%Y/%m/%d/')
|
||||
original_name = models.CharField(max_length=255) # 원본 파일명
|
||||
file_size = models.PositiveIntegerField() # 파일 크기 (bytes)
|
||||
uploaded_at = models.DateTimeField(auto_now_add=True)
|
||||
uploader_id = models.CharField(max_length=150, blank=True, default='') # 업로더 ID
|
||||
uploader_name = models.CharField(max_length=150, blank=True, default='') # 업로더 이름
|
||||
batch_id = models.CharField(max_length=36, blank=True, default='') # 업로드 배치 ID (같은 게시글 그룹)
|
||||
|
||||
def __str__(self):
|
||||
return self.original_name
|
||||
|
||||
|
||||
@receiver(pre_delete, sender=Attachment)
|
||||
def delete_attachment_file(sender, instance, **kwargs):
|
||||
"""Attachment 삭제 시 MinIO에서 파일도 삭제"""
|
||||
if instance.file:
|
||||
instance.file.delete(save=False)
|
||||
|
||||
Reference in New Issue
Block a user