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.
# zy: 评论表单模块 - 定义评论相关的表单类和验证逻辑
from django import forms
from django.forms import ModelForm
# zy: 导入评论模型,用于创建基于模型的自定义表单
from .models import Comment
# zy: 评论表单类 - 继承自ModelForm,用于处理评论的创建和验证
class CommentForm(ModelForm):
# zy: 父评论ID字段 - 用于实现评论回复功能
# 这是一个隐藏字段,不在页面显示,用于记录回复的父评论
parent_comment_id = forms.IntegerField(
widget=forms.HiddenInput, required=False)
# zy: 表单元数据配置类 - 定义表单与模型的关联关系
class Meta:
model = Comment
fields = ['body']