我创建了一个带有“parentId”和“email_notification”等自定义字段的评论应用程序。在模板中,comments
标签可以拉出我添加的项目,但“get_comment_form”标签不显示表单。另外,如何自定义该表单中的字段?
模型.py
from django.db import models
from django.contrib.comments.models import Comment
class CommentWithParent(Comment):
parentId = models.IntegerField(default = 0)
email_notification = models.BooleanField(default = False)
表格.py
from django import forms
from django.contrib.comments.forms import CommentForm
from mblog.my_comment.models import CommentWithParent
from django.db import models
class CommentWithParentForm(CommentForm):
parentId = models.IntegerField(default = 0)
email_notification = models.BooleanField(default = False)
def get_comment_model(self):
return CommentWithParent
def get_comment_create_data(self):
data = super(CommentWithParentForm, self).get_comment_create_data()
return data
def get_form(self):
return self
模板文件
{% load comments %}
{% get_comment_form for entry as form %}