Skip to content

Commit

Permalink
fix: Show latest title of pages (admin_manager)
Browse files Browse the repository at this point in the history
  • Loading branch information
fsbraun committed Oct 30, 2024
1 parent afdb591 commit 9d0ecda
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions djangocms_link/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from django.conf import settings
from django.contrib import admin
from django.core.exceptions import FieldError, PermissionDenied
from django.db.models import Q
from django.db.models import OuterRef, Q, Subquery
from django.http import JsonResponse
from django.urls import path
from django.views.generic.list import BaseListView
Expand Down Expand Up @@ -98,7 +98,7 @@ def serialize_result(self, obj):
"""
return {
"id": f"{obj._meta.app_label}.{obj._meta.model_name}:{obj.pk}",
"text": str(obj),
"text": getattr(obj, "__link_text__", str(obj)),
"url": obj.get_absolute_url(),
}

Expand All @@ -108,16 +108,18 @@ def get_queryset(self):
# django CMS 4.2+
qs = PageContent.admin_manager.filter(language=self.language).filter(
Q(title__icontains=self.term) | Q(menu_title__icontains=self.term)
).current_content().values_list("page_id", flat=True)
qs = Page.objects.filter(pk__in=qs).order_by("path")
).current_content()
qs = (Page.objects.filter(pk__in=qs.values_list("page_id", flat=True)).order_by("path")
.annotate(__link_text__=Subquery(qs.filter(page_id=OuterRef("pk")).values("title")[:1])))
if self.site:
qs = qs.filter(site_id=self.site)

Check warning on line 115 in djangocms_link/admin.py

View check run for this annotation

Codecov / codecov/patch

djangocms_link/admin.py#L115

Added line #L115 was not covered by tests
except (AttributeError, FieldError):
# django CMS 3.11 - 4.1
qs = get_manager(PageContent, current_content=True).filter(language=self.language).filter(
Q(title__icontains=self.term) | Q(menu_title__icontains=self.term)
).values_list("page_id", flat=True)
qs = Page.objects.filter(pk__in=qs).order_by("node__path")
)
qs = (Page.objects.filter(pk__in=qs.values_list("page_id", flat=True)).order_by("node__path")
.annotate(__link_text__=Subquery(qs.filter(page_id=OuterRef("pk")).values("title")[:1])))
if self.site:
qs = qs.filter(node__site_id=self.site)
return list(qs)
Expand Down

0 comments on commit 9d0ecda

Please sign in to comment.