I have two fields inheriting from the Wagtail Page
models, such as:
class ModelA(Page):
custom_field = models.CharField(max_length=255)
search_fields = Page.search_fields + [
index.SearchField("custom_field")
]
class ModelB(Page):
custom_field = models.CharField(max_length=255)
search_fields = Page.search_fields + [
index.SearchField("custom_field")
]
I am using the Wagtail database search backend, with Postgres as my DBMS:
WAGTAILSEARCH_BACKENDS = {
"default": {
"BACKEND": "wagtail.search.backends.database",
}
}
I would like to make a query from the Page
class that traverses the Page
model to find results from both ModelA
and ModelB
:
search_results = Page.objects.filter(custom_field="some value")
However, The above example throws an error:
django.core.exceptions.FieldError: Cannot resolve keyword 'custom_field' into field.
How can I search for values in custom_field
across multiple models inheriting from the Wagtail Page
model?