DJANGO COMMENTS_APP,我该如何使用它?发表评论后没有工作

时间:2011-10-24 10:25:44

标签: django comments

我尝试自定义django评论模块(删除字段url) 我创建空类VSComments和表单

from django import forms
from django.contrib.comments.forms import CommentForm
from vs_comments.models import VSComment

class VSCommentForm(CommentForm):
    """
    No url Form
   """
VSCommentForm.base_fields.pop('url')

__init__

from vs_comments.models import VSComment
from vs_comments.forms import VSCommentForm

def get_model():
    return VSComment

def get_form():
    return VSCommentForm

也是网址(r'^ comments /',include('django.contrib.comments.urls')),

将'vs_comments'和'django.contrib.comments'纳入INSTALLED_APPS和COMMENTS_APP ='vs_comments'

结果,我有正确的表单,没有url字段,但发布评论不起作用


添加到表单类

def get_comment_create_data(self):
# Use the data of the superclass, and remove extra fields
    return dict(
        content_type = ContentType.objects.get_for_model(self.target_object),
        object_pk    = force_unicode(self.target_object._get_pk_val()),
        comment      = self.cleaned_data["comment"],
        name         = self.cleaned_data["name"],
        submit_date  = datetime.datetime.now(),
        site_id      = settings.SITE_ID,
        is_public    = True,
        is_removed   = False,
    )

对于管理面板

class VSCommentAdmin(CommentsAdmin):
    """
    all like native comments
    """
admin.site.register(Comment, CommentsAdmin)

但是现在没有工作标记render_comment_list等。没有任何错误,只有空的结果 我该如何解决?

1 个答案:

答案 0 :(得分:0)

您是否有任何错误跟踪?

我认为它不起作用,因为VSCommentForm的验证使用了CommentForm的验证器,并且您的自定义表单中缺少“url”字段。

您应该阅读更多关于从其他表单继承的自定义表单及其验证:

https://docs.djangoproject.com/en/dev/topics/forms/#processing-the-data-from-a-form

https://code.djangoproject.com/wiki/CustomFormFields

https://docs.djangoproject.com/en/dev/ref/forms/validation/