diff --git a/apps/tag/models.py b/apps/tag/models.py index e250e474..28ff1183 100644 --- a/apps/tag/models.py +++ b/apps/tag/models.py @@ -5,7 +5,8 @@ from django.utils.translation import gettext_lazy as _ from configuration.models import TranslationSettings from location.models import Country -from utils.models import TJSONField +from elasticsearch_dsl.utils import AttrDict +from search_indexes.utils import OBJECT_FIELD_PROPERTIES class TagQuerySet(models.QuerySet): @@ -50,7 +51,9 @@ class Tag(models.Model): @property def label_indexing(self): - return self.translation.text + base_dict = self.translation.text if self.translation and isinstance(self.translation.text, dict) else {} + dict_to_index = {locale: base_dict.get(locale) for locale in OBJECT_FIELD_PROPERTIES} + return AttrDict(dict_to_index) objects = TagQuerySet.as_manager() @@ -155,7 +158,9 @@ class TagCategory(models.Model): @property def label_indexing(self): - return self.translation.text + base_dict = self.translation.text if self.translation and isinstance(self.translation.text, dict) else {} + dict_to_index = {locale: base_dict.get(locale) for locale in OBJECT_FIELD_PROPERTIES} + return AttrDict(dict_to_index) objects = TagCategoryQuerySet.as_manager()