You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
# FRR: 该模块定义评论相关的表单类, 用于处理用户提交评论的数据验证和交互,
# 继承Django的ModelForm实现与Comment模型的绑定, 简化表单开发流程。
from django import forms
from django . forms import ModelForm
from . models import Comment # 导入评论模型,用于表单与模型的关联
# FRR: 评论表单类, 继承ModelForm实现基于Comment模型的表单自动生成
class CommentForm ( ModelForm ) :
# FRR: 定义父评论ID字段, 用于支持评论回复功能
# 采用HiddenInput控件( 隐藏输入框) , 用户不可见但表单会提交该值
# required=False表示允许为空( 即该评论可以是一级评论, 无父评论)
parent_comment_id = forms . IntegerField (
widget = forms . HiddenInput , required = False )
# FRR: Meta内部类用于配置表单与模型的关联信息
class Meta :
model = Comment # 指定关联的模型为Comment
fields = [ ' body ' ] # 表单中需要包含的模型字段, 此处仅包含评论内容字段body