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.
tentest/doc/DjangoBlog/comments/forms.py

22 lines
1.0 KiB

This file contains ambiguous Unicode characters!

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)
# FRRMeta内部类用于配置表单与模型的关联信息
class Meta:
model = Comment # 指定关联的模型为Comment
fields = ['body'] # 表单中需要包含的模型字段此处仅包含评论内容字段body