1

プロジェクトで 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 を追加する必要がありますか?

コメントを生成するためにviews.pyを使用していないため、これを求めています(djangoドキュメントで説明されているように)

コメントにページネーションを追加するにはどうすればよいですか?

私は次のことを試しました:

  • views.py を使用したページネーション。ビューを作成し、それを使用することによって
  • UserExperience クラスで Class Based View を使用していることを確認しました (これについてはよくわかりませんが、完全に間違っている可能性があります..) 私もこの回答を試しました。クラスベースのビューのページネーションについてです。

それらのどれも機能しませんでした。

私のコメントを改ページするのを手伝ってください。

4

1 に答える 1