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

22 lines
667 B

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.

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']