Corrective implementation of implementation.md (containerized Django/Wagtail) #3
@@ -1,3 +1,5 @@
|
|||||||
|
from typing import Any, cast
|
||||||
|
|
||||||
from django.db.models import Count, Q
|
from django.db.models import Count, Q
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
from django.utils.translation import ngettext
|
from django.utils.translation import ngettext
|
||||||
@@ -49,22 +51,21 @@ class CommentViewSet(SnippetViewSet):
|
|||||||
add_to_admin_menu = True
|
add_to_admin_menu = True
|
||||||
|
|
||||||
def get_queryset(self, request):
|
def get_queryset(self, request):
|
||||||
return (
|
base_qs = self.model.objects.all().select_related("article", "parent")
|
||||||
self.model.objects.all()
|
# mypy-django-plugin currently crashes on QuerySet.annotate() in this file.
|
||||||
.select_related("article", "parent")
|
typed_qs = cast(Any, base_qs)
|
||||||
.annotate(
|
return typed_qs.annotate(
|
||||||
pending_in_article=Count(
|
pending_in_article=Count(
|
||||||
"article__comments",
|
"article__comments",
|
||||||
filter=Q(article__comments__is_approved=False),
|
filter=Q(article__comments__is_approved=False),
|
||||||
distinct=True,
|
distinct=True,
|
||||||
)
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
def pending_in_article(self, obj):
|
def pending_in_article(self, obj):
|
||||||
return obj.pending_in_article
|
return obj.pending_in_article
|
||||||
|
|
||||||
pending_in_article.short_description = "Pending (article)"
|
pending_in_article.short_description = "Pending (article)" # type: ignore[attr-defined]
|
||||||
|
|
||||||
|
|
||||||
register_snippet(CommentViewSet)
|
register_snippet(CommentViewSet)
|
||||||
|
|||||||
Reference in New Issue
Block a user