diff --git a/website/common/models.py b/website/common/models.py index 09a444e..b8e3b24 100644 --- a/website/common/models.py +++ b/website/common/models.py @@ -10,6 +10,7 @@ from wagtail.fields import StreamField from wagtail.images import get_image_model_string from wagtail.images.views.serve import generate_image_url from wagtail.models import Page, PageQuerySet +from wagtail.search import index from wagtail.snippets.models import register_snippet from website.common.utils import count_words @@ -113,7 +114,7 @@ class ListingPage(BasePage, BaseContentMixin): # type: ignore[misc] @register_snippet -class ReferralLink(models.Model): +class ReferralLink(models.Model, index.Indexed): url = models.URLField() name = models.CharField(max_length=64, unique=True) @@ -122,5 +123,7 @@ class ReferralLink(models.Model): FieldPanel("url"), ] + search_fields = [index.AutocompleteField("name"), index.SearchField("url")] + def __str__(self) -> str: return self.name diff --git a/website/contact/models.py b/website/contact/models.py index e321e02..0540092 100644 --- a/website/contact/models.py +++ b/website/contact/models.py @@ -3,6 +3,7 @@ from django.http.request import HttpRequest from django.utils.functional import cached_property from django.utils.text import slugify from wagtail.admin.panels import FieldPanel +from wagtail.search import index from wagtail.snippets.models import register_snippet from website.common.models import BaseContentMixin, BasePage @@ -10,7 +11,7 @@ from website.common.utils import TocEntry @register_snippet -class OnlineAccount(models.Model): +class OnlineAccount(models.Model, index.Indexed): name = models.CharField(max_length=64, unique=True) url = models.URLField() username = models.CharField(max_length=64) @@ -21,6 +22,12 @@ class OnlineAccount(models.Model): FieldPanel("url"), ] + search_fields = [ + index.AutocompleteField("name"), + index.FilterField("username"), + index.SearchField("url"), + ] + def __str__(self) -> str: return self.name diff --git a/website/settings.py b/website/settings.py index fa3453c..08d69f2 100644 --- a/website/settings.py +++ b/website/settings.py @@ -153,6 +153,8 @@ WAGTAIL_SITE_NAME = "website" WAGTAILSEARCH_BACKENDS = { "default": { "BACKEND": "wagtail.search.backends.database", + "AUTO_UPDATE": False, + "ATOMIC_REBUILD": True, } }