Add autocomplete for blog pots tags

This commit is contained in:
Jake Howard 2022-08-28 16:18:31 +01:00
parent c660e54bae
commit 47980032b0
Signed by: jake
GPG key ID: 57AFB45680EDD477
6 changed files with 18 additions and 5 deletions

View file

@ -21,3 +21,6 @@ drf-yasg
django-plausible
sentry-sdk
wagtail-favicon
# Pinned due to lack of Wagtail 3 support
git+https://github.com/wagtail/wagtail-autocomplete@03f46a0c256989690d0a43fc21fe0f37f9ede765

View file

@ -61,7 +61,8 @@ tablib[xls,xlsx]==3.2.1 # via wagtail
telepath==0.2 # via wagtail
uritemplate==4.1.1 # via coreapi, drf-yasg
urllib3==1.26.11 # via requests, sentry-sdk
wagtail==3.0.1 # via -r requirements/base.in, wagtail-draftail-snippet, wagtail-metadata
wagtail==3.0.1 # via -r requirements/base.in, wagtail-autocomplete, wagtail-draftail-snippet, wagtail-metadata
wagtail-autocomplete @ git+https://github.com/wagtail/wagtail-autocomplete@03f46a0c256989690d0a43fc21fe0f37f9ede765 # via -r requirements/base.in
wagtail-draftail-snippet==0.4.1 # via -r requirements/base.in
wagtail-favicon==0.2.0 # via -r requirements/base.in
wagtail-generic-chooser==0.4.1 # via -r requirements/base.in

View file

@ -90,7 +90,8 @@ types-urllib3==1.26.17 # via types-requests
typing-extensions==4.3.0 # via mypy
uritemplate==4.1.1 # via -r requirements/base.txt, coreapi, drf-yasg
urllib3==1.26.11 # via -r requirements/base.txt, requests, sentry-sdk
wagtail==3.0.1 # via -r requirements/base.txt, wagtail-draftail-snippet, wagtail-factories, wagtail-metadata
wagtail==3.0.1 # via -r requirements/base.txt, wagtail-autocomplete, wagtail-draftail-snippet, wagtail-factories, wagtail-metadata
wagtail-autocomplete @ git+https://github.com/wagtail/wagtail-autocomplete@03f46a0c256989690d0a43fc21fe0f37f9ede765 # via -r requirements/base.txt
wagtail-draftail-snippet==0.4.1 # via -r requirements/base.txt
wagtail-factories==3.1.0 # via -r requirements/dev.in
wagtail-favicon==0.2.0 # via -r requirements/base.txt

View file

@ -6,6 +6,7 @@ from django.utils import timezone
from django.utils.functional import cached_property
from modelcluster.fields import ParentalManyToManyField
from wagtail.admin.panels import FieldPanel
from wagtailautocomplete.edit_handlers import AutocompletePanel
from website.common.models import BaseContentPage, BaseListingPage
from website.common.utils import TocEntry, prefetch_for_listing
@ -38,7 +39,10 @@ class BlogPostListPage(BaseListingPage):
def get_listing_pages(self) -> models.QuerySet:
return prefetch_for_listing(
BlogPostPage.objects.descendant_of(self).live().order_by("-date", "title").prefetch_related("tags")
BlogPostPage.objects.descendant_of(self)
.live()
.order_by("-date", "title")
.prefetch_related("tags")
)
@property
@ -57,7 +61,7 @@ class BlogPostPage(BaseContentPage):
content_panels = BaseContentPage.content_panels + [
FieldPanel("date"),
FieldPanel("tags"),
AutocompletePanel("tags"),
]
@ -114,7 +118,8 @@ class BlogPostCollectionPage(BaseListingPage):
def get_listing_pages(self) -> models.QuerySet:
return prefetch_for_listing(
BlogPostPage.objects.child_of(self).live()
BlogPostPage.objects.child_of(self)
.live()
.prefetch_related("tags")
.order_by("-date", "title")
)

View file

@ -61,6 +61,7 @@ INSTALLED_APPS = [
"taggit",
"generic_chooser",
"wagtail_draftail_snippet",
"wagtailautocomplete",
"django_rq",
"drf_yasg",
"wagtail_favicon",

View file

@ -7,10 +7,12 @@ from wagtail.contrib.sitemaps.views import sitemap
from wagtail.documents import urls as wagtaildocs_urls
from wagtail.images.views.serve import ServeView
from wagtail_favicon.urls import urls as favicon_urls
from wagtailautocomplete.urls.admin import urlpatterns as autocomplete_admin_urls
from website.common.views import AllPagesFeed, KeybaseView, RobotsView, page_not_found
urlpatterns = [
path("admin/autocomplete/", include(autocomplete_admin_urls)),
path("admin/", include(wagtailadmin_urls)),
path("documents/", include(wagtaildocs_urls)),
path(