Fix comments snippet admin 500
Use an explicit Wagtail Column for pending_in_article in CommentViewSet list_display and add a regression test for /cms/snippets/comments/comment/. Fixes #37 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -4,7 +4,7 @@ from django.db.models import Count, Q
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.utils.translation import ngettext
|
||||
from wagtail import hooks
|
||||
from wagtail.admin.ui.tables import BooleanColumn
|
||||
from wagtail.admin.ui.tables import BooleanColumn, Column
|
||||
from wagtail.snippets.bulk_actions.snippet_bulk_action import SnippetBulkAction
|
||||
from wagtail.snippets.models import register_snippet
|
||||
from wagtail.snippets.permissions import get_permission_name
|
||||
@@ -45,7 +45,13 @@ class CommentViewSet(SnippetViewSet):
|
||||
model = Comment
|
||||
queryset = Comment.objects.all()
|
||||
icon = "comment"
|
||||
list_display = ["author_name", "article", BooleanColumn("is_approved"), "pending_in_article", "created_at"]
|
||||
list_display = [
|
||||
"author_name",
|
||||
"article",
|
||||
BooleanColumn("is_approved"),
|
||||
Column("pending_in_article", label="Pending (article)"),
|
||||
"created_at",
|
||||
]
|
||||
list_filter = ["is_approved"]
|
||||
search_fields = ["author_name", "body"]
|
||||
add_to_admin_menu = True
|
||||
@@ -62,11 +68,5 @@ class CommentViewSet(SnippetViewSet):
|
||||
)
|
||||
)
|
||||
|
||||
def pending_in_article(self, obj):
|
||||
return obj.pending_in_article
|
||||
|
||||
pending_in_article.short_description = "Pending (article)" # type: ignore[attr-defined]
|
||||
|
||||
|
||||
register_snippet(CommentViewSet)
|
||||
hooks.register("register_bulk_action", ApproveCommentBulkAction)
|
||||
|
||||
Reference in New Issue
Block a user