From 5a2c97c5ac382d9aecbe8c1e8ca60d08b57f5aef Mon Sep 17 00:00:00 2001 From: IrfanUddinAhmad Date: Tue, 9 Jan 2024 01:29:39 +0500 Subject: [PATCH] feat: Added content metadata tags for academy detail page --- .../migrations/0002_tag_content_metadata.py | 19 +++++++++++++++++++ enterprise_catalog/apps/academy/models.py | 3 ++- enterprise_catalog/apps/api/tasks.py | 6 ++++-- 3 files changed, 25 insertions(+), 3 deletions(-) create mode 100644 enterprise_catalog/apps/academy/migrations/0002_tag_content_metadata.py diff --git a/enterprise_catalog/apps/academy/migrations/0002_tag_content_metadata.py b/enterprise_catalog/apps/academy/migrations/0002_tag_content_metadata.py new file mode 100644 index 000000000..3c88f2c84 --- /dev/null +++ b/enterprise_catalog/apps/academy/migrations/0002_tag_content_metadata.py @@ -0,0 +1,19 @@ +# Generated by Django 4.2.7 on 2024-01-08 20:33 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('catalog', '0037_alter_historicalcontentmetadata_options_and_more'), + ('academy', '0001_initial'), + ] + + operations = [ + migrations.AddField( + model_name='tag', + name='content_metadata', + field=models.ManyToManyField(related_name='tags', to='catalog.contentmetadata'), + ), + ] diff --git a/enterprise_catalog/apps/academy/models.py b/enterprise_catalog/apps/academy/models.py index 169da13f4..60825b07e 100644 --- a/enterprise_catalog/apps/academy/models.py +++ b/enterprise_catalog/apps/academy/models.py @@ -8,7 +8,7 @@ from model_utils.models import TimeStampedModel from simple_history.models import HistoricalRecords -from enterprise_catalog.apps.catalog.models import EnterpriseCatalog +from enterprise_catalog.apps.catalog.models import ContentMetadata, EnterpriseCatalog class Tag(models.Model): @@ -19,6 +19,7 @@ class Tag(models.Model): """ title = models.CharField(max_length=255, help_text=_('Tag title')) description = models.TextField(help_text=_('Tag description.')) + content_metadata = models.ManyToManyField(ContentMetadata, related_name='tags') class Meta: verbose_name = _('Tag') diff --git a/enterprise_catalog/apps/api/tasks.py b/enterprise_catalog/apps/api/tasks.py index 46e002c81..28359174d 100644 --- a/enterprise_catalog/apps/api/tasks.py +++ b/enterprise_catalog/apps/api/tasks.py @@ -784,6 +784,7 @@ def _get_algolia_products_for_batch( 'enterprise_catalogs', 'enterprise_catalogs__academies', 'enterprise_catalogs__academies__tags', + 'enterprise_catalogs__academies__tags__content_metadata', ) # Retrieve ContentMetadata records for: @@ -856,8 +857,9 @@ def _get_algolia_products_for_batch( academy_uuids_by_key[content_key].add(str(academy.uuid)) academy_uuids_by_catalog_uuid[str(catalog.uuid)].add(str(academy.uuid)) for tag in associated_academy_tags: - academy_tags_by_key[content_key].add(str(tag.title)) - academy_tags_by_catalog_uuid[str(catalog.uuid)].add(str(tag.title)) + if tag.content_metadata.filter(content_key=content_key): + academy_tags_by_key[content_key].add(str(tag.title)) + academy_tags_by_catalog_uuid[str(catalog.uuid)].add(str(tag.title)) # Second pass. This time the goal is to capture indirect relationships on programs: # * For each program: