diff --git a/core/admin.py b/core/admin.py index da9e09b..fbd798c 100644 --- a/core/admin.py +++ b/core/admin.py @@ -13,6 +13,8 @@ from .models import ( FamilyTask, TodayPlan, SystemConfig, + PublicContentType, + PublicContent, ) @@ -96,3 +98,17 @@ class TodayPlanAdmin(admin.ModelAdmin): @admin.register(SystemConfig) class SystemConfigAdmin(admin.ModelAdmin): list_display = ('smtp_server', 'smtp_port', 'smtp_username', 'recipient_email', 'send_time', 'created_at') + + +@admin.register(PublicContentType) +class PublicContentTypeAdmin(admin.ModelAdmin): + list_display = ('name', 'created_at', 'updated_at') + search_fields = ('name',) + + +@admin.register(PublicContent) +class PublicContentAdmin(admin.ModelAdmin): + list_display = ('title', 'type', 'is_published', 'sort_order', 'created_at') + list_filter = ('type', 'is_published') + search_fields = ('title', 'content') + ordering = ('sort_order', '-created_at') diff --git a/core/forms.py b/core/forms.py index 66e9639..66f0914 100644 --- a/core/forms.py +++ b/core/forms.py @@ -8,7 +8,8 @@ from .models import ( FamilyTask, TodayPlan, SystemConfig, - FamilyMember + FamilyMember, + PublicContent ) class ReadingRecordForm(forms.ModelForm): @@ -109,4 +110,19 @@ class SystemConfigForm(forms.ModelForm): if not re.match(email_pattern, recipient_email): logger.warning(f"收件人邮箱格式不正确: {recipient_email}") raise forms.ValidationError("请输入有效的邮箱地址,格式如:example@domain.com") - return recipient_email \ No newline at end of file + return recipient_email + + +class PublicContentForm(forms.ModelForm): + """公开内容表单""" + class Meta: + model = PublicContent + fields = ['type', 'title', 'content', 'file', 'url', 'sort_order', 'is_published'] + widgets = { + 'type': forms.Select(attrs={'class': 'form-select'}), + 'title': forms.TextInput(attrs={'class': 'form-control', 'placeholder': '请输入标题'}), + 'content': forms.Textarea(attrs={'class': 'form-control', 'rows': 5, 'placeholder': '请输入内容'}), + 'file': forms.FileInput(attrs={'class': 'form-control'}), + 'url': forms.URLInput(attrs={'class': 'form-control', 'placeholder': '请输入链接地址'}), + 'sort_order': forms.NumberInput(attrs={'class': 'form-control', 'placeholder': '请输入排序值'}), + } \ No newline at end of file diff --git a/core/models.py b/core/models.py index 914b283..3c8d24d 100644 --- a/core/models.py +++ b/core/models.py @@ -216,3 +216,37 @@ class SystemConfig(models.Model): """获取系统配置,单例模式""" config, created = cls.objects.get_or_create(pk=1) return config + +class PublicContentType(models.Model): + """公开内容类型""" + name = models.CharField(max_length=20, unique=True, verbose_name="名称") + created_at = models.DateTimeField(auto_now_add=True, verbose_name="创建时间") + updated_at = models.DateTimeField(auto_now=True, verbose_name="更新时间") + + class Meta: + verbose_name = "公开内容类型" + verbose_name_plural = "公开内容类型" + ordering = ['name'] + + def __str__(self): + return self.name + +class PublicContent(models.Model): + """公开内容表""" + type = models.ForeignKey(PublicContentType, on_delete=models.CASCADE, verbose_name="类型") + title = models.CharField(max_length=200, verbose_name="标题") + content = models.TextField(blank=True, null=True, verbose_name="内容") + file = models.FileField(upload_to='public_files/', blank=True, null=True, verbose_name="上传文件") + url = models.URLField(blank=True, null=True, verbose_name="链接地址") + sort_order = models.IntegerField(default=0, verbose_name="排序") + is_published = models.BooleanField(default=True, verbose_name="是否发布") + created_at = models.DateTimeField(auto_now_add=True, verbose_name="创建时间") + updated_at = models.DateTimeField(auto_now=True, verbose_name="更新时间") + + class Meta: + verbose_name = "公开内容" + verbose_name_plural = "公开内容" + ordering = ['sort_order', '-created_at'] + + def __str__(self): + return f"{self.type.name} - {self.title}" diff --git a/core/templates/core/add_public_content.html b/core/templates/core/add_public_content.html new file mode 100644 index 0000000..88729d2 --- /dev/null +++ b/core/templates/core/add_public_content.html @@ -0,0 +1,76 @@ +{% extends 'core/base.html' %} + +{% block content %} + +
+

+ 添加公开内容 +

+ + 返回 + +
+ +
+
+
+
+
+ 填写公开内容信息 +
+
+
+
+ {% csrf_token %} + + {% for field in form %} +
+ + {{ field }} + {% if field.help_text %} +
{{ field.help_text }}
+ {% endif %} + {% for error in field.errors %} +
+ {{ error }} +
+ {% endfor %} +
+ {% endfor %} + +
+ + + 取消 + +
+
+
+
+
+
+{% endblock %} diff --git a/core/templates/core/base.html b/core/templates/core/base.html index a5679d7..5a156ba 100644 --- a/core/templates/core/base.html +++ b/core/templates/core/base.html @@ -449,6 +449,11 @@ 首页 + {% if user.is_authenticated %}