【发布时间】:2014-12-19 17:09:23
【问题描述】:
(对不起我的英语不好,我是一个破旧的法国人)
我尝试扩展 django 评论框架以添加喜欢/不喜欢系统。 阅读 the documentation 后,我已将此添加到我的 model.py 中:
from django.contrib.comments.models import Comment
class Commentslikes(Comment):
positif = models.IntegerField(default=0)
negatif = models.IntegerField(default=0)
启动命令python manage.py syncdb 后,django 创建了 cmetslikes mysql 表,其中包含 3 个列:comment_ptr_id、positif、否定。没关系。
在我的 view.py 文件中,我已经用这个覆盖了评论帖子视图:
def custom_comment_post(request, next=None, using=None):
#Post the comment and get the response
response = contrib_comments.post_comment(request, next, using)
if type(response) == HttpResponseRedirect:
redirect_path, comment_id = response.get('Location').split( '?c=' )
if comment_id:
comment = Comment.objects.get( id=comment_id )
if comment:
#For test, i try to add 20 positif likes, 10 dislikes and edit the comment with 'foo'
comment.positif = 20
comment.negatif = 10
comment.comment = 'foo'
comment.save()
return HttpResponseRedirect( redirect_path + "#c" + comment_id)
return response
然后我发布了一条测试评论。评论已用 'foo' 修改,但在 cmetslikes 表中没有添加任何行,其 id 为评论,positif 为 20,negatif 为 10。 中未添加评论的行cmets喜欢
我忘记或做了什么?
谢谢, 托马斯
【问题讨论】:
-
您好!只是为了让你知道,上周我和 Django 的核心贡献者之一在一起,他提到最好不要使用 Django 的 cmets,因为它们可能会被弃用。