From 1771b02afdea601a94dda6a2f48e701a173f974e Mon Sep 17 00:00:00 2001 From: Kuroshini Date: Fri, 20 Dec 2019 21:57:46 +0300 Subject: [PATCH] fix tags indexing --- apps/tag/models.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) 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()