localized cities #7

This commit is contained in:
Kuroshini 2020-01-28 12:35:23 +03:00
parent c0f3aca532
commit 029cd36b98
4 changed files with 19 additions and 7 deletions

View File

@ -1,20 +1,20 @@
"""Location app models."""
from functools import reduce
from json import dumps
from typing import List
from django.conf import settings
from django.contrib.gis.db import models
from django.contrib.postgres.fields import ArrayField
from django.db.models.signals import post_save
from django.db.transaction import on_commit
from django.dispatch import receiver
from django.utils.translation import gettext_lazy as _
from functools import reduce
from typing import List
from django.contrib.postgres.fields.jsonb import KeyTextTransform
from django.contrib.postgres.fields import ArrayField
from translation.models import Language
from utils.models import (ProjectBaseMixin, SVGImageMixin, TJSONField,
TranslatedFieldsMixin, get_current_locale,
IntermediateGalleryModelMixin, GalleryMixin)
IntermediateGalleryModelMixin)
class CountryQuerySet(models.QuerySet):
@ -180,6 +180,11 @@ class City(models.Model, TranslatedFieldsMixin):
def __str__(self):
return self.name
@property
def name_dumped(self):
"""Used for indexing as string"""
return dumps(self.name)
@property
def image_object(self):
"""Return image object."""

View File

@ -175,6 +175,7 @@ class EstablishmentDocument(Document):
'city': fields.ObjectField(
properties={
'id': fields.IntegerField(),
'name': fields.KeywordField(attr='name_dumped'),
'name_translated': fields.KeywordField(),
'is_island': fields.BooleanField(),
'country': fields.ObjectField(

View File

@ -44,6 +44,7 @@ class ProductDocument(Document):
attr='address.city',
properties={
'id': fields.IntegerField(),
'name': fields.KeywordField(attr='name_dumped'),
'name_translated': fields.KeywordField(),
'code': fields.KeywordField(),
'country': fields.ObjectField(

View File

@ -125,7 +125,12 @@ class CityDocumentShortSerializer(serializers.Serializer):
id = serializers.IntegerField()
code = serializers.CharField(allow_null=True)
# todo: index and use name dict field
name_translated = serializers.CharField()
name_translated = serializers.SerializerMethodField()
@staticmethod
def get_name_translated(obj):
get_translated_value(loads(obj.name))
class CountryDocumentSerializer(serializers.Serializer):