Some checks failed
Build And Test / build-and-push (push) Failing after 1m1s
- Post 모델 개선 (author_id, updated_at, view_count 등) - Tag 모델 및 태그 기능 추가 - 댓글 기능 추가 - API 확장 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
59 lines
1.6 KiB
Python
59 lines
1.6 KiB
Python
from django.db import models
|
|
from django.conf import settings
|
|
from django.contrib.auth.models import User
|
|
|
|
|
|
class Tag(models.Model):
|
|
"""태그 모델"""
|
|
name = models.CharField(max_length=50, unique=True)
|
|
created_at = models.DateTimeField(auto_now_add=True)
|
|
|
|
class Meta:
|
|
ordering = ['name']
|
|
|
|
def __str__(self):
|
|
return self.name
|
|
|
|
|
|
class Post(models.Model):
|
|
title = models.CharField(max_length=255)
|
|
content = models.TextField()
|
|
tags = models.ManyToManyField(Tag, related_name='posts', blank=True)
|
|
created_at = models.DateTimeField(auto_now_add=True)
|
|
updated_at = models.DateTimeField(auto_now=True)
|
|
author_id = models.CharField(max_length=150, blank=True, default='')
|
|
author_name = models.CharField(max_length=150)
|
|
|
|
class Meta:
|
|
ordering = ['-created_at']
|
|
|
|
def __str__(self):
|
|
return self.title
|
|
|
|
|
|
class Comment(models.Model):
|
|
"""댓글/대댓글 모델"""
|
|
post = models.ForeignKey(
|
|
Post,
|
|
related_name="comments",
|
|
on_delete=models.CASCADE
|
|
)
|
|
parent = models.ForeignKey(
|
|
'self',
|
|
null=True,
|
|
blank=True,
|
|
related_name="replies",
|
|
on_delete=models.CASCADE
|
|
) # 대댓글 지원
|
|
content = models.TextField()
|
|
author_id = models.CharField(max_length=150, blank=True, default='')
|
|
author_name = models.CharField(max_length=150)
|
|
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"Comment by {self.author_name} on {self.post.title}"
|