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}"