|
|
|
|
@ -1,13 +1,15 @@
|
|
|
|
|
from django import forms
|
|
|
|
|
from django.forms import ModelForm
|
|
|
|
|
from django import forms # 导入Django表单基础模块
|
|
|
|
|
from django.forms import ModelForm # 导入模型表单类,用于基于模型创建表单
|
|
|
|
|
|
|
|
|
|
from .models import Comment
|
|
|
|
|
from .models import Comment # 从当前应用导入Comment模型
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class CommentForm(ModelForm):
|
|
|
|
|
class CommentForm(ModelForm): # 定义评论表单类,继承自ModelForm
|
|
|
|
|
# 定义父评论ID字段,用于处理评论回复功能
|
|
|
|
|
# 使用HiddenInput小部件(前端隐藏),非必填(顶级评论不需要父评论ID)
|
|
|
|
|
parent_comment_id = forms.IntegerField(
|
|
|
|
|
widget=forms.HiddenInput, required=False)
|
|
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
|
model = Comment
|
|
|
|
|
fields = ['body']
|
|
|
|
|
class Meta: # 元数据配置
|
|
|
|
|
model = Comment # 指定表单关联的模型为Comment
|
|
|
|
|
fields = ['body'] # 表单包含的字段,仅包含评论内容字段body
|