Skip to content

Commit

Permalink
Remove the ManyToMany as it causes issues with Wagtail Admin (#599)
Browse files Browse the repository at this point in the history
  • Loading branch information
CamLamb authored May 15, 2024
1 parent f431d83 commit 4ce2318
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 67 deletions.
23 changes: 0 additions & 23 deletions src/content/migrations/0027_contentpage_topics.py

This file was deleted.

15 changes: 10 additions & 5 deletions src/content/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,11 +286,16 @@ class ContentPage(BasePage):
# and it's not worth the effort to refactor it.
#

topics = models.ManyToManyField(
"working_at_dit.Topic",
through="working_at_dit.PageTopic",
related_name="+",
)
@property
def topics(self):
from working_at_dit.models import Topic

topic_ids = self.page_topics.all().values_list("topic__pk", flat=True)
return Topic.objects.filter(pk__in=topic_ids)

@property
def topic_titles(self):
return [topic.title for topic in self.topics]

#
# Search
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@
"<FilterField: show_in_menus>",
"<FilterField: title>",
"<FilterField: translation_key>",
"<RelatedFields topics fields=['<SearchField: title>', '<SearchField: title_explicit>']>",
"<SearchField: excerpt>",
"<SearchField: excerpt_explicit>",
"<SearchField: search_categories>",
Expand All @@ -118,7 +117,9 @@
"<SearchField: search_headings_explicit>",
"<SearchField: search_title>",
"<SearchField: search_title_explicit>",
"<SearchField: title>"
"<SearchField: title>",
"<SearchField: topic_titles>",
"<SearchField: topic_titles_explicit>"
],
"<class 'news.models.NewsHome'>": [
"<AutocompleteField: title>",
Expand Down Expand Up @@ -229,7 +230,6 @@
"<FilterField: show_in_menus>",
"<FilterField: title>",
"<FilterField: translation_key>",
"<RelatedFields topics fields=['<SearchField: title>', '<SearchField: title_explicit>']>",
"<SearchField: excerpt>",
"<SearchField: excerpt_explicit>",
"<SearchField: search_content>",
Expand All @@ -238,7 +238,9 @@
"<SearchField: search_headings_explicit>",
"<SearchField: search_title>",
"<SearchField: search_title_explicit>",
"<SearchField: title>"
"<SearchField: title>",
"<SearchField: topic_titles>",
"<SearchField: topic_titles_explicit>"
],
"<class 'working_at_dit.models.HowDoI'>": [
"<AutocompleteField: title>",
Expand All @@ -258,7 +260,6 @@
"<FilterField: title>",
"<FilterField: translation_key>",
"<RelatedFields content_owner fields=['<SearchField: first_name_explicit>', '<SearchField: last_name_explicit>', '<SearchField: preferred_first_name_explicit>']>",
"<RelatedFields topics fields=['<SearchField: title>', '<SearchField: title_explicit>']>",
"<SearchField: content_contact_email_explicit>",
"<SearchField: excerpt>",
"<SearchField: excerpt_explicit>",
Expand All @@ -268,7 +269,9 @@
"<SearchField: search_headings_explicit>",
"<SearchField: search_title>",
"<SearchField: search_title_explicit>",
"<SearchField: title>"
"<SearchField: title>",
"<SearchField: topic_titles>",
"<SearchField: topic_titles_explicit>"
],
"<class 'working_at_dit.models.HowDoIHome'>": [
"<AutocompleteField: title>",
Expand Down Expand Up @@ -315,7 +318,6 @@
"<FilterField: title>",
"<FilterField: translation_key>",
"<RelatedFields content_owner fields=['<SearchField: first_name_explicit>', '<SearchField: last_name_explicit>', '<SearchField: preferred_first_name_explicit>']>",
"<RelatedFields topics fields=['<SearchField: title>', '<SearchField: title_explicit>']>",
"<SearchField: content_contact_email_explicit>",
"<SearchField: excerpt>",
"<SearchField: excerpt_explicit>",
Expand All @@ -325,7 +327,9 @@
"<SearchField: search_headings_explicit>",
"<SearchField: search_title>",
"<SearchField: search_title_explicit>",
"<SearchField: title>"
"<SearchField: title>",
"<SearchField: topic_titles>",
"<SearchField: topic_titles_explicit>"
],
"<class 'working_at_dit.models.Policy'>": [
"<AutocompleteField: title>",
Expand All @@ -345,7 +349,6 @@
"<FilterField: title>",
"<FilterField: translation_key>",
"<RelatedFields content_owner fields=['<SearchField: first_name_explicit>', '<SearchField: last_name_explicit>', '<SearchField: preferred_first_name_explicit>']>",
"<RelatedFields topics fields=['<SearchField: title>', '<SearchField: title_explicit>']>",
"<SearchField: content_contact_email_explicit>",
"<SearchField: excerpt>",
"<SearchField: excerpt_explicit>",
Expand All @@ -355,7 +358,9 @@
"<SearchField: search_headings_explicit>",
"<SearchField: search_title>",
"<SearchField: search_title_explicit>",
"<SearchField: title>"
"<SearchField: title>",
"<SearchField: topic_titles>",
"<SearchField: topic_titles_explicit>"
],
"<class 'working_at_dit.models.PoliciesHome'>": [
"<AutocompleteField: title>",
Expand Down Expand Up @@ -429,7 +434,6 @@
"<FilterField: show_in_menus>",
"<FilterField: title>",
"<FilterField: translation_key>",
"<RelatedFields topics fields=['<SearchField: title>', '<SearchField: title_explicit>']>",
"<SearchField: excerpt>",
"<SearchField: excerpt_explicit>",
"<SearchField: search_content>",
Expand All @@ -441,7 +445,9 @@
"<SearchField: search_tool_name>",
"<SearchField: search_tool_name_explicit>",
"<SearchField: search_tool_name_keyword>",
"<SearchField: title>"
"<SearchField: title>",
"<SearchField: topic_titles>",
"<SearchField: topic_titles_explicit>"
],
"<class 'tools.models.ToolsHome'>": [
"<AutocompleteField: title>",
Expand Down Expand Up @@ -487,7 +493,6 @@
"<FilterField: show_in_menus>",
"<FilterField: title>",
"<FilterField: translation_key>",
"<RelatedFields topics fields=['<SearchField: title>', '<SearchField: title_explicit>']>",
"<SearchField: excerpt>",
"<SearchField: excerpt_explicit>",
"<SearchField: search_content>",
Expand All @@ -496,7 +501,9 @@
"<SearchField: search_headings_explicit>",
"<SearchField: search_title>",
"<SearchField: search_title_explicit>",
"<SearchField: title>"
"<SearchField: title>",
"<SearchField: topic_titles>",
"<SearchField: topic_titles_explicit>"
],
"<class 'about_us.models.AboutUsHome'>": [
"<AutocompleteField: title>",
Expand All @@ -515,7 +522,6 @@
"<FilterField: show_in_menus>",
"<FilterField: title>",
"<FilterField: translation_key>",
"<RelatedFields topics fields=['<SearchField: title>', '<SearchField: title_explicit>']>",
"<SearchField: excerpt>",
"<SearchField: excerpt_explicit>",
"<SearchField: search_content>",
Expand All @@ -524,7 +530,9 @@
"<SearchField: search_headings_explicit>",
"<SearchField: search_title>",
"<SearchField: search_title_explicit>",
"<SearchField: title>"
"<SearchField: title>",
"<SearchField: topic_titles>",
"<SearchField: topic_titles_explicit>"
],
"<class 'networks.models.NetworksHome'>": [
"<AutocompleteField: title>",
Expand Down Expand Up @@ -571,7 +579,6 @@
"<FilterField: title>",
"<FilterField: translation_key>",
"<RelatedFields content_owner fields=['<SearchField: first_name_explicit>', '<SearchField: last_name_explicit>', '<SearchField: preferred_first_name_explicit>']>",
"<RelatedFields topics fields=['<SearchField: title>', '<SearchField: title_explicit>']>",
"<SearchField: content_contact_email_explicit>",
"<SearchField: excerpt>",
"<SearchField: excerpt_explicit>",
Expand All @@ -581,7 +588,9 @@
"<SearchField: search_headings_explicit>",
"<SearchField: search_title>",
"<SearchField: search_title_explicit>",
"<SearchField: title>"
"<SearchField: title>",
"<SearchField: topic_titles>",
"<SearchField: topic_titles_explicit>"
],
"<class 'country_fact_sheet.models.CountryFactSheetHome'>": [
"<AutocompleteField: title>",
Expand Down
14 changes: 4 additions & 10 deletions src/networks/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import peoplefinder.models as pf_models
from content.models import ContentOwnerMixin, ContentPage
from extended_search.index import DWIndexedField as IndexedField
from extended_search.index import RelatedFields


class NetworksHome(ContentPage):
Expand Down Expand Up @@ -112,15 +111,10 @@ class Network(ContentOwnerMixin, ContentPage):
base_form_class = NetworkForm

indexed_fields = [
RelatedFields(
"topics",
[
IndexedField(
"title",
tokenized=True,
explicit=True,
),
],
IndexedField(
"topic_titles",
tokenized=True,
explicit=True,
),
] + ContentOwnerMixin.indexed_fields

Expand Down
2 changes: 1 addition & 1 deletion src/working_at_dit/migrations/0008_alter_pagetopic_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
class Migration(migrations.Migration):

dependencies = [
("content", "0027_contentpage_topics"),
("content", "0026_alter_contentpage_body"),
("working_at_dit", "0007_guidance_content_contact_email_and_more"),
]

Expand Down
14 changes: 4 additions & 10 deletions src/working_at_dit/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

from content.models import BasePage, ContentOwnerMixin, ContentPage, Theme
from extended_search.index import DWIndexedField as IndexedField
from extended_search.index import RelatedFields


class WorkingAtDITHome(ContentPage):
Expand Down Expand Up @@ -133,15 +132,10 @@ class Meta:

class PageWithTopics(ContentPage):
indexed_fields = [
RelatedFields(
"topics",
[
IndexedField(
"title",
tokenized=True,
explicit=True,
),
],
IndexedField(
"topic_titles",
tokenized=True,
explicit=True,
),
]

Expand Down

0 comments on commit 4ce2318

Please sign in to comment.