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.
from django import forms
from django.forms import ModelForm
from .models import Comment
class CommentForm(ModelForm):
# 用于存储父评论的 ID(实现评论回复功能)
# 该字段不会显示到页面中(HiddenInput),允许为空(一级评论时为空)
parent_comment_id = forms.IntegerField(
widget=forms.HiddenInput,
required=False
)
class Meta:
# 指定该表单操作的模型为 Comment
model = Comment
# 只允许用户输入评论内容(body)
# 其他字段(如 author、article、parent_comment)将在视图中自动赋值
fields = ['body']