diff --git a/forum/form.py b/forum/form.py index 05ff949..001e88d 100644 --- a/forum/form.py +++ b/forum/form.py @@ -37,14 +37,14 @@ def __init__(self, *args, user=None, **kwargs): class Meta: model = Collection - fields = ['name', 'description'] + fields = ['name', 'content'] labels = { 'name': '合集名称', - 'description': '描述', + 'content': '描述', } widgets = { 'name': forms.TextInput(attrs={'class': 'form-control'}), - 'description': forms.Textarea(attrs={'rows': 3, 'class': 'form-control'}), + 'content': forms.Textarea(attrs={'rows': 3, 'class': 'form-control'}), } def save(self, commit=True): diff --git a/forum/models.py b/forum/models.py index 0880d48..d9e5afd 100644 --- a/forum/models.py +++ b/forum/models.py @@ -3,9 +3,6 @@ from .markdown import MarkdownModel -import markdown -import bleach - # Create your models here. class Item(MarkdownModel): @@ -47,11 +44,9 @@ def __str__(self): return f"{self.author} comment {self.post}" -class Collection(models.Model): +class Collection(MarkdownModel): owner = models.ForeignKey(User, on_delete=models.CASCADE, related_name='collections') name = models.CharField(max_length=100) - description = models.TextField(blank=True, default='') - description_html = models.TextField(editable=False, blank=True) created_at = models.DateTimeField(auto_now_add=True) class Meta: @@ -60,19 +55,6 @@ class Meta: def __str__(self): return self.name - def save(self, *args, **kwargs): - if self.description: - html = markdown.markdown(self.description, extensions=MarkdownModel.MARKDOWN_EXTENSIONS) - self.description_html = bleach.clean( - html, - tags=MarkdownModel.allowed_tags, - attributes=MarkdownModel.allowed_attrs, - protocols=MarkdownModel.ALLOWED_PROTOCOLS, - ) - else: - self.description_html = '' - super().save(*args, **kwargs) - class CollectionPost(models.Model): collection = models.ForeignKey(Collection, on_delete=models.CASCADE, related_name='collection_posts') diff --git a/forum/templates/base.html b/forum/templates/base.html index cec2719..76a6596 100644 --- a/forum/templates/base.html +++ b/forum/templates/base.html @@ -122,7 +122,7 @@ function updateThemeIcon() { const icon = document.getElementById('theme-icon'); const isDark = document.documentElement.getAttribute('data-bs-theme') === 'dark'; - icon.className = 'bi ' + (isDark ? 'bi-sun' : 'bi-moon-stars'); + icon.className = 'bi ' + (isDark ? 'bi-moon' : 'bi-sun'); } updateThemeIcon(); diff --git a/forum/templates/forum/collection_detail.html b/forum/templates/forum/collection_detail.html index 465b31f..e460b55 100644 --- a/forum/templates/forum/collection_detail.html +++ b/forum/templates/forum/collection_detail.html @@ -4,8 +4,8 @@ {% block content %}
diff --git a/forum/templates/forum/collection_form.html b/forum/templates/forum/collection_form.html index 7a483bb..86118f6 100644 --- a/forum/templates/forum/collection_form.html +++ b/forum/templates/forum/collection_form.html @@ -1,9 +1,9 @@ {% extends 'base.html' %} -{% block title %}{{ title }}{% endblock %} +{% block title %}创建合集{% endblock %} {% block content %} -