如何向django.contrib.comments添加分页?

如何向django.contrib.comments添加分页?,django,django-comments,django-pagination,Django,Django Comments,Django Pagination,我在项目中使用Django的评论框架来处理电影评论: 我的My_comments_app/models.py如下所示: from django.db import models from django.contrib.comments.models import Comment class UserExperience(Comment): experience = models.CharField('User Experience', max_length=20) # pag

我在项目中使用Django的评论框架来处理电影评论:

我的My_comments_app/models.py如下所示:

from django.db import models
from django.contrib.comments.models import Comment

class UserExperience(Comment):
    experience = models.CharField('User Experience', max_length=20)

    # paginate_by = 4 | This does not work !!

    def __unicode__(self):
        return self.user.username
我的my_comment_app/forms.py看起来像:

from django import forms
from .models import UserExperience
from django.contrib.comments.forms import CommentForm

from movies.models import Movie
from django.contrib.comments.moderation import CommentModerator, moderator


class UserExperienceForm(CommentForm):
    experience = forms.CharField(max_length=20)

    def get_comment_model(self):
        return UserExperience

    def get_comment_create_data(self):
        data = super(UserExperienceForm, self).get_comment_create_data()
        data['experience'] = self.cleaned_data['experience']
        return data

class MovieCommentModerator(CommentModerator):
    email_notification = False
    auto_close_field = "start_date"
    close_after = 31

moderator.register(Movie, MovieCommentModerator)
我应该在何时何地添加paginate_by=4以获取我的评论系统paginate请求

我这样问是因为我没有使用任何views.py来生成我的评论(如django文档中所述)

如何在注释中添加分页

我尝试了以下方法:

  • 。通过创建视图并使用其
  • 看到我在UserExperience类中使用了基于类的视图(我不确定,我可能完全错了…),我也尝试了答案。这是关于基于类的视图的分页
他们都没有工作。 帮助我在views.py文件中对我的评论进行分页。

def CommentView(request):
    allComments = UserExperience.objects.all()
    paginator = Paginator(comments, 10)
    comment = paginator.page(1)

“comment”的值将是[0…9]comment。

我已经试过了,不起作用。因为django.contrib.comments不使用任何views.py来生成注释。如果我们想添加任何新字段和表单,它只有一个models.py。Paginator用于将模型生成页面。它不会被实现,paginate_by=4应该在views.py中使用,我已经看到了。这是上面问题中的链接。如果可以,请添加views.py,我将尝试更改它。你不能只使用过滤器来计算模板中的分页吗