fix tags indexing (final)

This commit is contained in:
Kuroshini 2019-12-20 22:07:19 +03:00
parent 35673f9ad0
commit d97972a3ef
2 changed files with 11 additions and 6 deletions

View File

@ -143,6 +143,8 @@ class EstablishmentDocument(Document):
'weekday_display': fields.KeywordField(attr='get_weekday_display'),
'closed_at': fields.KeywordField(attr='closed_at_str'),
'opening_at': fields.KeywordField(attr='opening_at_str'),
# 'closed_at_datetime': fields.DateField(attr='closed_at'),
# 'opening_at_datetime': fields.DateField(attr='opening_at'),
}
))
address = fields.ObjectField(

View File

@ -5,8 +5,7 @@ from django.utils.translation import gettext_lazy as _
from configuration.models import TranslationSettings
from location.models import Country
from elasticsearch_dsl.utils import AttrDict
from search_indexes.utils import OBJECT_FIELD_PROPERTIES
from utils.models import IndexJSON
class TagQuerySet(models.QuerySet):
@ -52,8 +51,10 @@ class Tag(models.Model):
@property
def label_indexing(self):
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)
index = IndexJSON()
for k, v in base_dict.items():
setattr(index, k, v)
return index
objects = TagQuerySet.as_manager()
@ -159,8 +160,10 @@ class TagCategory(models.Model):
@property
def label_indexing(self):
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.keys()}
return AttrDict(dict_to_index)
index = IndexJSON()
for k, v in base_dict.items():
setattr(index, k, v)
return index
objects = TagCategoryQuerySet.as_manager()