This commit is contained in:
21
blog/models.py
Normal file
21
blog/models.py
Normal file
@ -0,0 +1,21 @@
|
||||
from django.db import models
|
||||
from django.conf import settings
|
||||
from markdown_it import MarkdownIt
|
||||
from taggit.managers import TaggableManager
|
||||
|
||||
class Post(models.Model):
|
||||
title = models.CharField(max_length=200) # 제목
|
||||
content = models.TextField() # 본문 (마크다운 저장)
|
||||
summary = models.CharField(max_length=2000, blank=True, null=True) # 요약
|
||||
created_at = models.DateTimeField(auto_now_add=True) # 작성일
|
||||
updated_at = models.DateTimeField(auto_now=True) # 수정일
|
||||
tags = TaggableManager()
|
||||
author = models.ForeignKey(settings.AUTH_USER_MODEL, null=True, on_delete=models.CASCADE)
|
||||
|
||||
def render_markdown(self):
|
||||
"""마크다운을 HTML로 변환"""
|
||||
md = MarkdownIt()
|
||||
return md.render(self.content)
|
||||
|
||||
def __str__(self):
|
||||
return self.title
|
Reference in New Issue
Block a user