71 lines
2.0 KiB
Python
71 lines
2.0 KiB
Python
"""Search indexes serializers."""
|
|
from rest_framework import serializers
|
|
from django_elasticsearch_dsl_drf.serializers import DocumentSerializer
|
|
from search_indexes.documents import EstablishmentDocument, NewsDocument
|
|
from search_indexes.utils import get_translated_value
|
|
|
|
|
|
class NewsDocumentSerializer(DocumentSerializer):
|
|
"""News document serializer."""
|
|
|
|
title_translated = serializers.SerializerMethodField(allow_null=True)
|
|
subtitle_translated = serializers.SerializerMethodField(allow_null=True)
|
|
description_translated = serializers.SerializerMethodField(allow_null=True)
|
|
|
|
class Meta:
|
|
"""Meta class."""
|
|
|
|
document = NewsDocument
|
|
fields = (
|
|
'id',
|
|
'title',
|
|
'subtitle',
|
|
'description',
|
|
'web_url',
|
|
'title_translated',
|
|
'subtitle_translated',
|
|
'description_translated',
|
|
)
|
|
|
|
@staticmethod
|
|
def get_title_translated(obj):
|
|
return get_translated_value(obj.title)
|
|
|
|
@staticmethod
|
|
def get_subtitle_translated(obj):
|
|
return get_translated_value(obj.subtitle)
|
|
|
|
@staticmethod
|
|
def get_description_translated(obj):
|
|
return get_translated_value(obj.description)
|
|
|
|
|
|
# todo: country_name_translated
|
|
class EstablishmentDocumentSerializer(DocumentSerializer):
|
|
"""Establishment document serializer."""
|
|
|
|
description_translated = serializers.SerializerMethodField(allow_null=True)
|
|
|
|
class Meta:
|
|
"""Meta class."""
|
|
|
|
document = EstablishmentDocument
|
|
fields = (
|
|
'id',
|
|
'name',
|
|
'description',
|
|
'public_mark',
|
|
'toque_number',
|
|
'price_level',
|
|
'description_translated',
|
|
'tags',
|
|
'address',
|
|
'collections',
|
|
'establishment_type',
|
|
'establishment_subtypes',
|
|
)
|
|
|
|
@staticmethod
|
|
def get_description_translated(obj):
|
|
return get_translated_value(obj.description)
|